[mercury-users] "some" and existential types

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Oct 3 18:37:28 AEST 1999


On 03-Oct-1999, Robert Ernst Johann JESCHOFNIK <rejj at cat.cs.mu.OZ.AU> wrote:
> On Sun, 3 Oct 1999, Fergus Henderson wrote:
> 
> > There's an easy solution here: just declare `anything' to be an
> > instance of `printable':
> > 
> > 	:- instance printable(anything) where [
> > 		pred(print/3) is print_anything
> > 	].
> > 
> > 	:- pred print_anything(anything::in, io__state::di, io__state::uo)
> > 		is det.
> > 	print_anything(thing(X)) --> print(X).
> > 
> > Then you can write `print_anythings(Xs) --> list__foldl(print, Xs)'
> > and it should work just fine.
> 
> should this be "print_anythings(Xs) --> list__foldl(print_anything, Xs)."?

Either will work.

The former is actually slightly more general; with that code, you can
use the more polymorphic type declaration

	:- pred print_anythings(list(T)) <= printable(T).

whereas with the latter you need to use the type declaration

	:- pred print_anythings(list(anything)).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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