[mercury-users] list functor style functions
Michael Day
mikeday at corplink.com.au
Fri Nov 12 22:00:32 AEDT 1999
> I may be missing Michael's point, but I wondered why the following wasn't
> sufficient for the example problem:
I get the feeling I'm missing your point completely Ralph, 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
I'm thinking, as the S isn't being used as a constructor? Currently I'm
using this, which is hopefully not too far fetched:
:- typeclass sequence(S) where [
func [] = S(T),
func [T | S(T)] = S(T)
].
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 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...
> (this was compiled with -E, which only removes from the error report the
> suggestion that one recompile with -E!) What have I done wrong?
It would be nice if it only bothered to display -E if there really was
extra information to be gained from using it :)
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