[mercury-users] Passing a multi-mode higher order predicate
Jeff Thompson
jeff at thefirst.org
Wed Feb 8 18:16:24 AEDT 2012
On 2/7/2012 8:04 PM, Julien Fischer wrote:
>>>> 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?
>>>
>>> Can't you just use mode-specific clauses?
>>>
>>> ... with bagof/3 itself, for example
>>>
>>> bagof(X::in, Pred::in(pred(in, in) is semidet), Bag::out) :- ...
>>> bagof(X::out, Pred::in(pred(out, in) is nondet), Bag::in) :- ...
>>
>> This is precisely how I came across my recent question. Suppose I
>> want to call bagof inside the following predicate:
>> :- pred myTest(int, list(int)).
>> :- mode myTest(in, out) is semidet.
>> :- mode myTest(out, out) is nondet.
>> myTest(X, Xs) :- bagof(X, list.member, Xs).
>>
>> As you point out, I can't just pass a multi-mode predicate of
>> list.member like this. Do I have to implement myTest for each mode
>> just to pass the right mode of list.member?
>
> Yes.
OK. I used a solution I'm happy with: not to re-implement myTest for all
modes, but to make a function which takes X as an argument and checks if
it in or free>>free and returns the right mode of list.member.
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