[m-dev.] Default typeclass method implementations
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Oct 2 15:43:41 AEDT 2000
On 29-Sep-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> It occurs to me (this was discussed ages ago) that it shouldn't
> be too hard to extend the current typeclass scheme to include
> default method implementations.
Yes.
> For example (inventing lots of
> syntax and assuming functional dependencies)...
>
> :- typeclass seq(S, T) given (S >> T) where [
> func head(S) = T,
> func tail(S) = S,
> func cons(T, S) = S,
> func empty = S,
> func singleton(T) = S `defaults_to` [
> singleton(X) = cons(X, empty)
> ],
> func append(S, S) = S `defaults_to` [
> append(Xs, Ys) =
> ( if Xs = empty then Ys else cons(head(Xs),
> append(tail(Xs), Ys)) )
> ],
> func reverse(S) = S `defaults_to` [
> reverse(Xs) =
> ( if Xs = empty
> then empty
> else append(reverse(tail(Xs)),
> singleton(head(Xs))) )
> ]
> ].
>
> Any thoughts?
The syntax you've suggested above won't work well for multi-moded
methods.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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