[mercury-users] Higher-order insts
David Overton
dmo at cs.mu.OZ.AU
Wed May 19 18:17:45 AEST 2004
On Wed, May 19, 2004 at 02:26:21PM +1000, Peter Hawkins wrote:
> Hi...
>
> Is there a way of storing a closure including higher-order insts in a data
> structure and getting it back again? I'm trying to do this:
>
> :- type something.
>
> :- inst mypred = (pred(in, out) is semidet).
> :- type mypred = (pred(something, set(something))).
> :- mode mypredin == (mypred >> mypred).
> :- mode mypredout == (free >> mypred).
>
> :- type athing ---> a(
> moo :: mypred
> ).
>
> :- func new_athing(mypred) = athing.
> :- mode new_athing(mypredin) = out.
> new_athing(Moo) = a(Moo).
>
> :- func get_moo(athing) = moo.
> :- mode get_moo(in) = mypredout.
> get_moo(AThing) = AThing ^ Moo.
>
> But it fails with an error like this:
> things.m:098: In clause for `get_moo(in) = (things.mypredout)'
> :
> things.m:098: mode error: argument 2 did not get sufficiently instantiated.
> things.m:098: Final instantiatedness of `HeadVar__2' was `ground',
> things.m:098: expected final instantiatedness was `(pred((ground -> ground),
> (free -> ground)) is semidet)'.
>
> Is what I am trying to do possible?
The mode declaration for `get_moo/1' needs to contain the higher-order
inst information. E.g.:
:- inst athing ---> a(mypred).
:- mode get_moo(in(athing)) = mypredout.
You probably also want
:- mode new_athing(mypredin) = out(athing).
David
--
David Overton
WWW: http://www.overtons.id.au/
Mobile Phone (UK): +44 7799 344 322
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list