[mercury-users] list functor style functions

Ralph Becket rbeck at microsoft.com
Fri Nov 12 22:58:24 AEDT 1999


> I get the feeling I'm missing your point completely Ralph,

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?

> but I'm
> beginning to see the shape of the code I was thrashing around 
> looking for,
> something like:
> 
> > ====================================================
> > :- module sequences.
> > 
> > :- interface.
> > 
> > :- 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,

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

> and which removes the need for this:
> 
> > :- instance sequence(my_list(T), T).
> 
> although I would have phrased it like this:
> 
> :- instance sequence(my_list, T).
> 
> and now just need this:
> 
> :- instance sequence(my_list).

I don't see what this gains us - surely my_list is parametric in some type?

> I thought that universal instance declarations would be necessary at
> first, but the things I was trying to do did not require it. 
> That kind of
> thing will no doubt be useful elsewhere, but if it creates horrendous
> implementation problems I won't hold my breath for it...

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

Cheers,

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