[mercury-users] Typeclasses & parameters

Jörg Roman Rudnick joerg.rudnick at t-online.de
Mon May 28 19:47:11 AEST 2007

Hi Tomas,

here is one workaround which might do for you:

1) You declare (possibly) typeclasses `iVertex(V)', `iEdge(E)' for Nodes 
& Edges.

2) You declare existential types `xVertex', `xEdge' (see chapter 11 of 
the manual).

3) You make `xVertex' & `xEdge' themselves satisfy `iVertex(V)', resp. 
`iEdge(E)', writing appropriate wrappers & an unwrappers.

4) You declare a typeclass

:-typeclass tree(V, E) <= ( iVertex(V), iEdge(E) ) where [...]

with instance

:-instance tree(xVertex, xEdge) where [...].

Then, you should only have to code an instance of `iVertex(V)', resp. 
`iEdge(E)', for each node, resp. edge type.

There is one especially aggravating drawback with this approach: I am 
afraid it might not be possible to have constructor methods upon 
existential types (at least, it should be quite tricky...) -- but, after 
all, it's the same with Java interfaces and the like so still you get a 
rather strong expressibility... ;-)

All the best & lots of fun with Mercury,

mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list