[mercury-users] typeclass question #2

Terrence Brannon princepawn at earthlink.net
Thu May 3 13:28:08 AEST 2001


:- type rgb
        ---> rgb(
                int,
                int,
                int
        ).

:- type coloured_coordinate
        ---> coloured_coordinate(
                float,
                float,
                rgb
        ).

.... I would have done this a different way:

:- type coordinate --->
  coordinate (float,float).

type colored_coordinate %correct spelling :-)
   ---> colored_coordinate(
           coordinate,
           rgb
	   ).


... then I tried to figure out how to write methods to do the two
levels of indirection but
  a - the samples directory has no typeclasses
  b - the library directory has one: enum, but only an interface and
      no implementation.

... but here is my guess

:- pred set_color_position(coordinate(X,Y), R, G, B, colored_coordinate(M,N,R2,G2,B2)).
:- mode set_color_position(             in,in,in,in, out) is det.

pred set_color_position(coordinate(X,Y), R, G, B, colored_coordinate(M,N,R2,G2,B2)) =
   M=X, N=Y, R2=R, G2=G, B2 = B.

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