[mercury-users] Existential types and list.map
Ralph Becket
rafe at cs.mu.OZ.AU
Fri Jul 29 13:21:15 AEST 2005
Peter Hawkins, Friday, 29 July 2005:
> Mark Brown wrote:
>
> >This is not type safe because there is nothing in the signature of
> >get_thing
> >that guarantees that all of the elements in list Y have the same type. To
> >build such a list you would need to have get_thing return a structure that
> >contains an existentially typed value. For example, the signature for
> >get_thing could be:
> >
> > :- func get_thing(int) = univ.
> >
> >Then Y would have type list(univ), which would be okay.
> >
> >
> >
> Yes, but I want to put typeclass constraints on the resulting type, so I
> can't use univ. As far as I can see, my only option is to define a new
> list type, which is just hideous.
No, a data constructor can have existentially quantified arguments:
:- type thing ---> some [T] thing(T) => thingable(T).
:- func get_thing(int) = thing.
get_thing(X) = 'new thing'(X).
And now you can have lists of things.
-- Ralph
--------------------------------------------------------------------------
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