<p>Mercury has trouble inferring higher-order modes.  You'll want to write out</p>
<p>:- mode cnt(pred(out) is nondet) = out.</p>
<p>- Chris</p>
<p><blockquote type="cite">On Apr 13, 2011 1:22 PM, "Vladimir Gubarkov" <<a href="mailto:xonixx@gmail.com">xonixx@gmail.com</a>> wrote:<br><br>Hi,<div><br></div><div>I'm trying to create predicate for counting the whole number of solutions. I'm trying</div>
<div><br></div><div><div>:- module t2.</div><div>:- interface.</div><div>:- import_module io.</div><div>
:- pred main(io::di, io::uo) is det.</div><div><br></div><div>:- implementation.</div><div><br></div><div>:- import_module list, solutions, int.</div><div><br></div><div><br></div><div>take(E, !L) :- list.delete(!.L, E, !:L).</div>

<div><br></div><div>:- pred perm(list(T), list(T)).</div><div>:- mode perm(in, out) is multi.</div><div>perm([], []).</div><div>perm(L @ [_|_], [E|EE]) :- take(E, L, L1), t2.perm(L1, EE).</div><div><br></div><div>cnt(P) = N :- </div>

<div><span style="white-space:pre-wrap">  </span>promise_equivalent_solutions [N] (</div><div><span style="white-space:pre-wrap">               </span>unsorted_aggregate(P, (pred(_V::in, Acc0:int::in, Acc:int::out) is det :-</div>
<div><span style="white-space:pre-wrap">                  </span>Acc = Acc0 + 1), 0, N)</div><div><span style="white-space:pre-wrap">   </span>).</div><div><br></div><div>main(!IO) :- write_int(cnt(t2.perm(1..5)), !IO).</div>
</div><div><br></div><div>I want it to show me answer=120, but getting compilation error:</div><div><br></div><div><div>Making Mercury\cs\t2.c</div><div>t2.m:011: Inferred :- pred take(T, list.list(T), list.list(T)).</div>

<div>t2.m:011: Inferred :- mode take(out, in, out).</div><div>t2.m:018: Inferred :- func cnt((pred T)) = int.</div><div>t2.m:020: In clause for `cnt(in) = out':</div><div>t2.m:020:   in call to predicate `solutions.unsorted_aggregate'/4:</div>

<div>t2.m:020:   mode error: arguments</div><div>t2.m:020:   `TypeInfo_for_T, TypeCtorInfo_19, P, V_8, V_9, N' have the</div><div>t2.m:020:   following insts:</div><div>t2.m:020:     ground,</div><div>t2.m:020:     unique(<type_ctor_info for .int/0>),</div>

<div>t2.m:020:     ground,</div><div>t2.m:020:     /* unique */(pred((ground >> ground), (ground >> ground), (free</div><div>t2.m:020:     >> ground)) is det),</div><div>t2.m:020:     unique(0),</div><div>

t2.m:020:     free</div><div>t2.m:020:   which does not match any of the modes for predicate</div><div>t2.m:020:   `solutions.unsorted_aggregate'/4.</div><div>Error: system command received signal 1.</div><div>** Error making `Mercury\cs\t2.c'.</div>

</div><div><br></div><div>Is it possible to make it work?</div><div><br></div><div>Thank you,</div><div>Vladimir</div>
</blockquote></p>