[mercury-users] Newbie questions about typeclasses

David Overton dmo at cs.mu.OZ.AU
Wed Apr 25 23:22:41 AEST 2001


Hi,

On Tue, Apr 24, 2001 at 11:26:50AM -0400, Critterrathman at aol.com wrote:
> That was the part I was trying to figure out.  I couldn't figure out how to 
> get the mode declared, and didn't think to put both the predicate and mode 
> within the typeclass definition.  Works like a charm when you declare the 
> mode.  I end up with typeclasses that look like:
> 
> :- typeclass shapeClass(This) where [
>    func getX(This) = int,
>    mode getX(in) = out is det,
> 
>    ..... cut .....
> 
>    pred draw(This, io__state, io__state),
>    mode draw(in, di, uo) is det
> ].

One further point that you may not be aware of (judging by this code
and the example you've posted on your web page):  It is generally not
necessary to give mode declarations for _functions_ since, if no mode
declaration is given, a default mode is assumed where every argument
has mode 'in', the result has mode 'out' and the determinism is 'det'.
This applies equally for type class method declarations, higher order
function terms and normal function declarations.

So in your code above, the line

	mode getX(in) = out is det

could be removed since this mode will be assumed by default anyway.
The mode declaration for the predicate, however, is necessary since
there are no default modes for predicates.


David
-- 
David Overton      Department of Computer Science & Software Engineering
PhD Student        The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159    http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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