[mercury-users] Passing a multi-mode higher order predicate
Jeff Thompson
jeff at thefirst.org
Mon Feb 6 12:09:29 AEDT 2012
On 2/5/2012 7:52 AM, Julien Fischer wrote:
>
> Hi,
>
> 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.
Thanks for the clarification. I see that in the language reference
manual now. I came across this because I am trying to convert a code
base of Prolog to Mercury which deeply uses bagof in multiple modes. My
example comes from the following use case where Prolog can easily handle
the following code whether X is var or nonvar:
test(X, Bag) :- bagof(X, member(X, [1, 2]), Bag).
If X is ground, then it uses list.member(int::in, list(int)::in). But
if it is nonvar, then it uses list.member(int::out, list(int)::in). I
cannot figure out an efficient way to duplicate bagof, much less the
case where there are multiple modes. I know Mercury disputes the
soundness of the semantics of bagof, but is there a paper which
describes how to achieve the same multi-mode behavior?
Thanks,
- Jeff
--------------------------------------------------------------------------
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