<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">I’ve found a way to implement my code:<br class=""><div class=""><br class=""></div><div class=""><div class=""><i class="">:- module animals1b.</i></div><div class=""><i class="">:- interface.</i></div><div class=""><i class="">:- import_module io.</i></div><div class=""><i class="">:- pred main(io::di, io::uo) is det.</i></div><div class=""><i class="">:- implementation.</i></div><div class=""><i class="">:- import_module string, list, int.</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- type kinds ---> cat; dog.</i></div><div class=""><i class="">:- type pet</i></div><div class=""><i class=""> ---> pet(</i></div><div class=""><i class=""> name :: string,</i></div><div class=""><i class=""> size :: int,</i></div><div class=""><i class=""> kind :: kinds</i></div><div class=""><i class=""> ).</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- func large_lower_bound = int.</i></div><div class=""><i class="">large_lower_bound = 34.</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- func relative_size(pet) = string.</i></div><div class=""><i class="">relative_size(pet(_, Size, cat)) = (if Size > large_lower_bound then "large cat" else "small cat").</i></div><div class=""><i class="">relative_size(pet(_, Size, dog)) = (if Size > large_lower_bound then "large dog" else "small dog").</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">main(!IO) :-</i></div><div class=""><i class=""> foldl(animals1b.print, Animals, !IO),</i></div><div class=""><i class=""> Animals = [</i></div><div class=""><i class=""> pet("Bill", 26, cat),</i></div><div class=""><i class=""> pet("Harry", 27, cat),</i></div><div class=""><i class=""> pet("Mary", 33, cat),</i></div><div class=""><i class=""> pet("Steve", 31, cat),</i></div><div class=""><i class=""> pet("Fido", 26, dog),</i></div><div class=""><i class=""> pet("Fred", 33, dog),</i></div><div class=""><i class=""> pet("Henri", 44, dog),</i></div><div class=""><i class=""> pet("Jane", 55, dog),</i></div><div class=""><i class=""> pet("Rover", 45, dog),</i></div><div class=""><i class=""> pet("Tom", 68, dog)</i></div><div class=""><i class=""> ].</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- pred print(pet::in, io::di, io::uo) is det.</i></div><div class=""><i class="">print(P, !IO) :-</i></div><div class=""><i class=""> io.format("%s is sized %d: it's a %s.\n",</i></div><div class=""><i class=""> [s(P^name), i(P^size), s(relative_size(P))], !IO).</i></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">Le 14 mai 2021 à 13:22, Philippe de Rochambeau <<a href="mailto:phiroc@free.fr" class="">phiroc@free.fr</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">I would like to create a predicate called <i class="">small</i> which works for the <i class="">cat</i> and <i class="">dog</i><span style="font-style: normal;" class=""> types show below.</span></div><div class=""><br class=""></div><div class="">I’ve tried to create a generic predicate, but to no avail:</div><div class=""><br class=""></div><div class=""><div class=""><i class="">:- pred cat(T::out) is multi.</i></div><div class=""><i class="">cat(X) :- small(X).</i></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Any help would be much appreciated.</div><div class=""><br class=""></div><div class="">Many thanks.</div><div class=""><br class=""></div><div class="">Philippe</div><div class=""><br class=""></div><div class="">-----------------------------------------------------------------------------------</div><div class=""><br class=""></div><div class=""><div class=""><i class="">:- implementation.</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- type cat</i></div><div class=""><i class=""> ---> bill</i></div><div class=""><i class=""> ; harry</i></div><div class=""><i class=""> ; mary</i></div><div class=""><i class=""> ; steve.</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- type dog</i></div><div class=""><i class=""> ---> fido</i></div><div class=""><i class=""> ; fred</i></div><div class=""><i class=""> ; henry</i></div><div class=""><i class=""> ; jane</i></div><div class=""><i class=""> ; rover</i></div><div class=""><i class=""> ; tom.</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- pred cat(cat::out) is multi.</i></div><div class=""><i class="">cat(Cat) :- small(Cat).</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- pred dog(dog::out) is multi.</i></div><div class=""><i class="">dog(Dog) :- small(Dog).</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">:- pred small(cat).</i></div><div class=""><i class="">:- mode small(in) is semidet.</i></div><div class=""><i class="">:- mode small(out) is multi.</i></div><div class=""><i class="">small(steve).</i></div><div class=""><i class="">small(harry).</i></div></div></div></div></blockquote></div><br class=""></div></div></body></html>