[mercury-users] list functor style functions

Michael Day mikeday at corplink.com.au
Fri Nov 12 23:45:14 AEDT 1999


> Just to make sure we're both talking about the same problem, the name of
> the game is to use [something]classes to support a list-like interface to
> sequence types?

I haven't been concentrating exclusively on sequences, but they're
certainly a very compelling example that show up the lack of a number of
nice features, so yes.

> > > :- typeclass sequence(S, T) where [
> > >         func [] = S,
> > >         func [T | S] = S
> > > ].
> > 
> > Passing the T as the second parameter doesn't really achieve 
> > anything here
> 
> But it does: it says that S and T stand in some relation.  If I remove it,
> as you do,

Given your type class declaration, here are some possible instance
declarations:

:- instance sequence(my_list(T), T).
:- instance sequence(my_list(int), int).
:- instance sequence(my_list(T), int).

However the only one that is actually valid mercury is the last, the first
two instance declarations are not permitted. Worse still, the last
declaration is really not useful, as it states that you can take ints out
of a list of anything.

> > :- typeclass sequence(S) where [
> > 	func [] = S(T),
> > 	func [T | S(T)] = S(T)
> > ].
> 
> Then you need constructor classes and it's not clear to me why that is
> necessary.

My example is equally useless as Mercury does not support constructor
classes. But if the implementation and semantic difficulties of extending
instance declarations are as severe as Fergus asserts, perhaps constructor
classes are an easier solution? Plus being useful for other things that I
could perhaps dredge up an example for if pressed. Hmm.

> Now I'm confused.  What's wrong with my solution?  (Other than it doesn't
> compile...)

Well, that's it as far as I can see. It doesn't compile and it most likely
won't for the forseeable future. As to whether it's the code or the
compiler that's wrong, that's for wiser heads than mine. I guess that
leads to the question,

	Are constructor classes as used above significantly more likely to
	be implemented than universal type class instance declarations?

Think I'll have to go and re-read those constructor class posts from last
week so I don't get completely lost...

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