[m-dev.] Typeclasses and constructor classes.

Ralph Becket rbeck at microsoft.com
Wed Sep 20 22:14:33 AEDT 2000


>From David Glen JEFFERY on 20/09/2000 11:55:22
> 
> This is more likely to be what is allowed:
> 
> :- typeclass sequence(S, T) where [
> 	... % same method types
> ].
> 
> > and
> > 
> > :- instance sequence(list(T)).
> 
> ...becomes
> 
> :- instance sequence(list, T).

This looks a mite dodgy to me - in Mercury list/0 and list/1
would be separate types, yet this syntax would be ambiguous.

Perhaps a better syntax is

:- typeclass sequence(S/1) where [
	func map(func(T) = U, S(T)) = S(U),
	...
].

or at the very least

:- typeclass sequence(S(T)) where [
	func map(func(T) = U, S(T)) = S(U) <= sequence(S(U)),
	...
].

and hence

:- instance sequence(list(T)).

> I'm sure that sent off alarm bells in a few people's heads. The instance
> I've written above wouldn't be accepted according to Mercury's current
> rules
> for ensuring that instances do not overlap. (ie. top level type
> constructors
> must be bound).

With the above scheme, the problem disappears for some types (e.g. list/1).

> This turned out to be such a problem for the Haskell people that
> `functional
> dependencies' were born. Check out
> 	http://www.cse.ogi.edu/~mpj/fds.html
> for an overview. There was also a paper published on this earlier in the
> year... I don't have a reference handy though, sorry.

Thanks, I'll check that out.

> (We are making quite a bit of use of type classes in HAL, particularly
> as
> a way of modelling constraint solvers (a `plug and play' interface).
> I've
> got this sneaking suspicion that very, very soon we are going to realise
> that
> we need constructor classes to do what we're trying to do... in which
> case
> I will probably wind up doing the implementation anyway, both in HAL
> and in our target language Mercury).

If it doesn't look likely, is there any chance of handing this over
to someone who is willing and able?  I'd like to start porting the
Edison library, but that is pretty much impossible with typeclasses as
they stand.

Cheers,

Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list