[mercury-users] Record syntax

Simon Taylor stayl at cs.mu.OZ.AU
Thu Jan 20 13:40:53 AEDT 2000


> However I just read  that the record syntax does not allow two labels with
> the same name in a given module:
> 
> Does this mean I can't have
> 
> :-type node1--->n1(id::int,....).
> :-type node2--->n2(id::int,....).
> 
> in a single module?

That's right.

> Is there a very good reason for this?

The compiler only allows a single function with a given name
and arity in each module.

One desirable feature of record syntax is that changes to the
representation of a type which cause an attribute to be computed
on demand by a user-defined function, rather than stored in the
type, shouldn't require changes to the uses of the attribute.

If multiple fields in a module were allowed to have the same name
that wouldn't always be possible, because the user-defined functions
would need to have different names.

> If I create a sub module for node2:
> 
> I'd have to use N1^id and N2^node2__id but the compiler should  know that N1
> has type node1 and N2 has type node2, so node2 seems redundant and I don't
> want to have to write this...

You don't have to -- the compiler will work out which one you mean from
the types.

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