[mercury-users] list functor style functions

Ralph Becket rbeck at microsoft.com
Fri Nov 12 21:22:14 AEDT 1999


I may be missing Michael's point, but I wondered why the following wasn't
sufficient for the example problem:

====================================================
:- module sequences.

:- interface.

:- typeclass sequence(S, T) where [
        func [] = S,
        func [T | S] = S
].

:- type my_list(T).

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

:- implementation.

:- type my_list(T) ---> nil ; cons(T, my_list(T)).

:- instance sequence(my_list(T), T) where [
        func([]/0) is my_nil,
        func('.'/2) is my_cons
].

:- func my_nil = my_list(T).

my_nil = nil.

:- func my_cons(T, my_list(T)) = my_list(T).

my_cons(X, Xs) = cons(X, Xs).
====================================================

When I compile this, I get

Error: expected type in instance declaration to be a functor with variables
as a
rgs: _1.
Error: expected type in instance declaration to be a functor with variables
as a
rgs: _1.

(this was compiled with -E, which only removes from the error report the
suggestion that one recompile with -E!)  What have I done wrong?

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