[mercury-users] Typeclasses & parameters

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Wed May 30 08:12:18 AEST 2007


Dear Nick, you wrote to Tomas:

>4) You declare a typeclass
>:-typeclass tree(V, E) <= ( iVertex(V), iEdge(E) ) where [...]
>with instance
>:-instance tree(xVertex, xEdge) where [...].

I followed this thread and did a bit of exploratory programming down
this path.  Although I got it working, I'm not sure this will be to
Tomas' liking: the existential types allow for a heterogeneous tree,
and, although Tomas requested a pred that gave edge labels for any
type of tree, I think he was looking for a homogeneous tree (one 
cartesian type per each tree, instead of N cartesian types per
each tree).  Although heterogeneity allows homogeneity (which
gives Tomas an answer in his domain, "solving" his problem), if 
homogeneity is required, then the existential "solution" will compile
systems that fail this domain requirement (creating new problems).

I also tried the functional dependency approach, but ran right back
into the issue raised in a separate thread about functional dependencies
and typeclass constraints.

This issue and other similar ones raised in threads (the restriction
against typeclassing polymorphic types, "functional insts", etc) seem to
be addressed by dependently-typed languages ... perhaps a review of the
things Mercury does so well (modes, insts, types, typeclasses, determinism)
vis-a-vis dependent types could yield a language that is more expressive
with a stronger type correctness?

Just a thought.

On the other hand, the standard library already has the polymorphic tree
type defined, which allows the user to extract edge and "vertex" ("node"
in the standard library) information.  Aren't the things that Tomas is attempting
already defined in the library?

Sincerely,
Doug Auclair

--------------------------------------------------------------------------
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