[mercury-users] Passing a multi-mode higher order predicate

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Feb 6 02:52:56 AEDT 2012


On Sat, 4 Feb 2012, Jeff Thompson wrote:

> Hello again.  In the program below, the compiler gives the following error 
> due to "test(list.member)".
> test.m:010: In clause for `main(di, uo)':
> test.m:010:   in argument 1 of call to predicate `test.test'/1:
> test.m:010:   mode error: variable `V_6' has instantiatedness `free',
> test.m:010:   expected instantiatedness was `(pred((ground >> ground), 
> (ground
> test.m:010: >> ground)) is semidet)'.
> The predicate list.member exists with the correct mode, so why does the 
> compiler say the argument is free?

In general, the current Mercury implementation. does *not* support
creating higher-order terms from multi-moded predicates.   See the
``Creating higher-order terms'' of the reference manual (section 8.1).
(There is an exception to this in the case where the are some curried
higher-order arguments, but that does not apply here.)   The compiler
usually generates a more useful error message for this; I'm not sure
why it doesn't in this case.

> :- module test.
> :- interface.
> :- import_module io.
> :- pred main(io__state::di, io__state::uo) is cc_multi.
> :- implementation.
> :- import_module int, list.
> main(!IO) :-
>  if test(list.member) then io.write_string("yes", !IO) else 
> io.write_string("no", !IO).

You need to use an explicit lambda expression to specify the mode, e.g.

     Pred = (pred(E::in, Es::in) is semidet :- list.member(E, Es)),
     ( if test(Pred) then
          io.write_string("yes", !IO)
          io.write_string("no", !IO)

mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list