[mercury-users] Polymorphism / Type classes

David Jeffery dgj at cs.mu.OZ.AU
Fri Jun 15 01:47:25 AEST 2001

On 15-Jun-2001, David Jeffery <dgj at cs.mu.oz.au> wrote:
> > Is there a simple explanation for why 2nd order polymorphism is
> > hard?
> A simple explanation? Not really.
> [...]
> There would still be some complications to the type checker, but it is 
> essentially doable. Not sure what the repurcussions on the rest of the
> compiler might be... I imagine quite a few things might break.

Actually, it's a whole lot worse than this. I have just looked at some notes
that I made about this a while back, and I now remember why I put this one in
the Too Hard Basket.

If we have the following pred declarations:

:- pred p1(pred(int, list(int))).
:- pred p2(all [T] pred(T, list(T))).

then for the following code fragment:

q :-

q is *not* well typed if p1 is producing X, and p2 is consuming it. (After
all, you're trying to pass something that only works on ints when it is
meant to work on all Ts).

q *is* well typed if p2 is producing X, and p1 is consuming it (ie. if
the conjuncts are re-ordered). (No problem here: p2 produces something
polymorphic and you just apply it to ints).


David Jeffery (dgj at cs.mu.oz.au) | If you want to build a ship, don't drum up 
PhD student,                    | people together to collect wood or assign 
Dept. of Comp. Sci. & Soft. Eng.| them tasks and work, but rather teach them 
The University of Melbourne     | to long for the endless immensity of the sea.
Australia                       | -- Antoine de Saint Exupery
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