[mercury-users] Newbie questions about typeclasses

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Apr 25 03:16:59 AEST 2001


On 24-Apr-2001, Robert Bossy <bossy at ccr.jussieu.fr> wrote:
> > 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.

Yes, that's correct.

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

Yes.

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