[mercury-users] Newbie questions about typeclasses

Robert Bossy bossy at ccr.jussieu.fr
Wed Apr 25 03:07:47 AEST 2001


> I gather also that there is a write form of the accessor using the
> ':=' for
> the assignment but I can't figure out how to use it.  Currently I'm
> writing
> it as:
> 
>   setX_Circle(circleRecord(_,Y,Radius), X) = circleRecord(X, Y,
> Radius).
> 
> which spins off a new record based on the values in the input record.
> Anyhow, is there a way to use the set accessor to make this shorter,
> if not
> more efficient?

setX_Circle(This,X) = This^x := X.

does exactly the same: it reads as "a circleRecord identical to This but
x set to X".

I don't think it's more efficient, just more concise. As Peter Ross
pointed out earlier (in thread "Optional fields in datatype - How to
represent?"), the compiler does a lot of tranformations in your code and
both ways to write should expand to the same intermediate code.
The same applies to several other "syntax choices" like using DCG
notation or not, writing a single long clause with disjunctions (';') or
several simple clauses... Am I right?

This is very nice (mercury is nice) because you concentrate on more
efficient algorithms and readable code rather than more efficient code.



Robert Bossy
bossy at ccr.jussieu.fr
--------------------------------------------------------------------------
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