[mercury-users] Type error in higher-order predicate and existential type
François Degrave
fde at info.fundp.ac.be
Tue Nov 6 20:57:09 AEDT 2007
Nicholas Nethercote a écrit :
> On Tue, 6 Nov 2007, Peter Ross wrote:
>
>>> Using a higher-order predicate, I get an type error and I don't
>>> understand where it comes from. Here is a much simplified version of
>>> the
>>> predicate I wrote :
>>>
>>> :- pred higher_order_pred(pred(T,T),T).
>>> :- mode higher_order_pred(in(pred(in, out) is semidet),out) is semidet.
>>> higher_order_pred(HOPred,Result) :- call(HOPred,5,Result).
>>>
>> For the line
>>
>> call(HOPred, 5, Result)
>>
>> the first argument to the higher-order pred is an int, but you said in
>> the type declaration that it can be any T thus the error.
>>
>> :- pred higher_order_pred(pred(int,int),int).
>>
>> fixes the error.
>>
>> Another explanation is that T in the type declaration can be any T,
>> but the body of the predicate restricts the set of allowable T's to be
>> int only.
>
> Here's what may be an easier way to think about it -- what would
> happen you passed in an HOPred with the type 'pred(float,float)'?
>
> Nick
>
Ok, thanks everyone, that's clear for me now!
--------------------------------------------------------------------------
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
--------------------------------------------------------------------------
--------------------------------------------------------------------------
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