[mercury-users] typeclass issue #1

Fergus Henderson fjh at cs.mu.OZ.AU
Thu May 3 14:31:49 AEST 2001


On 02-May-2001, Terrence Brannon <princepawn at earthlink.net> wrote:
> 
> from the manual we have:
> 
> :- type coordinate
>         ---> coordinate(
>                 float,           % X coordinate
>                 float            % Y coordinate
>         ).
> 
> :- instance point(coordinate) where [
>         pred(coords/3) is coordinate_coords,
>         func(translate/3) is coordinate_translate
> ].
> 
> 
> in my eyes, there is a lack of ability to make the word 'coordinate'
> implicit throughout this code body. It seems tedious, error-prone and
> against the idea of packaging related concepts, to have to prefix every
> method relating to type coordinate in typeclass instance point with
> the word coordinate.

That example in the manual was written before we added the following extension
in Mercury 0.10:

 | * Type class methods can now be defined by listing the clauses
 |   directly in the instance declaration.

When we added that extension, we updated the manual to describe the
extension, but we didn't change that example, or point out that it
can also be written more concisely.

The way I'd recommended writing this in Mercury 0.10 and greater is
by putting the clauses for coordinate_coords/3 and coordinate_translate/3
directly in the instance declarations as clauses for coords/3
and translate/3, and omitting the declarations for coordinate_coords/3 and
coordinate_translate/3.

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