[mercury-users] /* unique */ and plain higher order instantiatedness

Julien Fischer juliensf at cs.mu.OZ.AU
Sat Mar 4 04:02:17 AEDT 2006



On Fri, 3 Mar 2006, Ondrej Bojar wrote:

> Hi.
>
> I'd like to define the following function to convert plain functions
> into predicates that threads IO along the computation.
>
> :- func ignore_io(func(A, B)=C) = (pred(A, B, C, io, io)).
> :- mode ignore_io(func(in, in)=out is det)
>            = (pred(in, in, out, di, uo)is det).
>
> ignore_io(Func)
>    = (pred(A::in, B::in, C::out, I::di, I::uo) is det :- C = Func(A, B)).
>
> However the compiler complains:
>
> suggest_for_lemma.m:169: In clause for `ignore_io((func(in, in) = out is
> det)) = (pred(in, in, out, di, uo) is det)':
> suggest_for_lemma.m:169:   mode error in unification of `HeadVar__2' and
> lambda expression.
> suggest_for_lemma.m:169:   Variable `HeadVar__2' has instantiatedness
> `(pred((ground >> ground), (ground >> ground), (free >> ground), (unique
>  >> clobbered), (free >> unique)) is det)',
> suggest_for_lemma.m:169:   lambda expression has instantiatedness `/*
> unique */(pred((ground >> ground), (ground >> ground), (free >> ground),
> (unique >> clobbered), (free >> unique)) is de
> t)'.
>
> (Sorry for unreadable dump.) The only difference in instantiatednesses
> lies in prefixing the (pred...) with "/* unique */" or not.
>
> Am I doing something wrong?

The mode of the return value should be:

	out((pred(in, in, out, di, uo) is det))

and you've omitted the determinism annotation from the mode declaration
as well.  The following version compiles without complaint:



	:- func ignore_io((func(A, B) = C)) = (pred(A, B, C, io, io)).
	:- mode ignore_io(in((func(in, in) = out is det)))
		= out((pred(in, in, out, di, uo) is det)) is det.

	ignore_io(Func) =
		(pred(A::in, B::in, C::out, I::di, I::uo) is det :-
			C = Func(A, B)
		).

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