[mercury-users] Type error in higher-order predicate and existential type

Peter Ross pro at missioncriticalit.com
Tue Nov 6 09:24:21 AEDT 2007


On 11/6/07, François Degrave <fde at info.fundp.ac.be> wrote:
> Dear all,
>
>
> 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.




> And here's the error returned by the compiler :
>
> reordering.m:023: In clause for predicate `reordering.higher_order_pred/2':
> reordering.m:023:   in argument 2 (i.e. argument 1 of the called
> predicate) of higher-order predicate call:
> reordering.m:023:   type error: argument has type `int',
> reordering.m:023:   expected type was `(some [T] T)'.
>
> Where does this existential type (some [T] T) come from? And what should
> I change in what I wrote to make it OK?
>
>
> Thank you in advance,
>
>
> François
>
>
>
> --------------------------------------------------------------------------
> 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
> --------------------------------------------------------------------------
>


-- 
Peter Ross - Mission Critical Australia
AU: +61 424 651 834
BE: +32 485 482 559

--------------------------------------------------------------------------
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