[mercury-users] Polymorphism / Type classes
Michael Day
mikeday at corplink.com.au
Tue Jun 19 10:42:41 AEST 2001
> You have written the type of your 'with_useful' method as:
>
> all [U] pred with_useful(pred(U, U), F, F) <= useful(U)
>
> whereas what I think you are trying to say is something like
>
> pred with_useful(all [U] pred(U, U) <= useful(U), F, F)
Right, that's exactly what I wrote, in fact. Though of course it didn't
work...
> First, you can re-arrange your code so that the type that you call
> `do_stuff' with is bound at the point at which you call with_useful. Not
> always easy to do...
I managed to do it this time; still seems like this polymorphism would be
nice to have sometimes though.
> The other way is to use a trick with type classes. This trick takes advantage
> of the fact that the implementation of type classes effectively uses
> second order polymorphism to encode the type class dictionaries (although
> this is hidden in a layer of C code because our compiler back end can't
> handle second order polymorphism at the moment).
Yeah that's what I was doing at first, but it seemed like unnecessary
indirection. Oh well.
> Enough babble from me... you just managed to ask me a question about
> exactly the material that I'm currently writing in my thesis...
Nice to make an on-topic post for once :)
Michael
--------------------------------------------------------------------------
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