[mercury-users] maintaining state in instances of typeclasses

Fergus Henderson fjh at cs.mu.OZ.AU
Wed May 16 14:32:17 AEST 2001


On 15-May-2001, Terrence Brannon <princepawn at earthlink.net> wrote:
> Fergus Henderson writes:
>  > But type classes in Mercury are not the same as classes in OOP languages.
>  > In OOP languages, an instance of a class is an object.
>  > In Mercury, an instance of a type class is a type.
> 
> Is inheritance of typeclasses possible?

Essentially you get interface inheritance, but not implementation inheritance.

Instead of implementation inheritance, you'd generally use containment
and delegation.

	:- typeclass my_class(T) where [
		func foo(T) = int,
		...
	].

	:- type base_type ---> ...
	:- instance my_class(base_type).

	:- type derived_type ---> derived(base :: base_type).

	:- instance my_class(derived_type) where [
		foo(Derived) = foo(Derived^base),
		...
	].

> Well how about things like:
> 
> 1 - SUPER - calling a method in the "superclass" of a type

As you can see in the example above, no explicit keyword is
required to delegate a method to a contained object.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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