[mercury-users] Document Giving Help with Typeclasses

David Glen JEFFERY dgj at cs.mu.OZ.AU
Fri Nov 3 15:59:35 AEDT 2000


On 03-Nov-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > EXISTENTIAL TYPES
> > 
> > Q. What's the difference between existential types and polymorphic types?
> > 
> > A. A polymorphic type is decided by the caller, so
> > 
> > :- func make_pair(T) = {T, T}.
> > make_pair(X) = {X, X}.
> > 
> > has to work for *any* type T that is passed to it by the caller.
> 
> Add something like:
> 
> It is as if there is an explicit `for all [T]' attached to the
> function's type signature. 
> 
> Note that this is why a value of type T needs to be an input parameter.

Perhaps this is nitpicking, but `T' being universally quantified doesn't mean
that the corresponding value has to be an input.
Eg. 
	:- pred init_empty_list(list(T)).
	:- mode init_empty_list(out) is det.
	init_empty_list([]).

Then again, there aren't (and can't be) any Ts created by init_empty_list;
there is only a list(T). I guess there is a `theorem for free' there somewhere.

But then, with dynamic typing, we lose that propery as well: if you could,
for example, dynamically check whether `T' is bound to `int', then you
could create a non-empty list of integers in that case.

Enough rambling from me.

(More comments on Ralph's posting soon, hopefully...)


dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student,                    | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.|     With sufficient formality
The University of Melbourne     |     The sheerist banality
Australia                       | Will be hailed by the critics: "Miraculous!"
                                |     -- Anon.
--------------------------------------------------------------------------
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