[mercury-users] Records

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 3 02:48:22 AEDT 1999


On 02-Nov-1999, Robert Ernst Johann JESCHOFNIK <rejj at cat.cs.mu.OZ.AU> wrote:
> On Tue, 2 Nov 1999, Simon Taylor wrote:
> 
> > :- type t
> > 	---> t(
> > 		field1 :: int,
> > 		field2 :: string,
> > 		field3 :: t2
> > 	).
> 
> This is just my opinion, but I think it may be a bit clearer if the type
> were to come before the field name,
> 
> :- type t --->
> 	t(
> 	   int    :: field1,
> 	   string :: field2,
> 	   t2     :: field3
> 	).
> 
> etc.

Pascal and many other languages influenced by it (Ada, Eiffel, Sather,
Modula, ...) use the syntax `<name> : <type>'.  I think it will be
clear enough.

It seems to me that for a reader the name is of primary importance,
rather than the type, and so I think the name should come first.

> > 	% field extraction.
> > 	Field1 = X ^ field1,		% Field1 = 1.
> > 	Field5 = X ^ field3 ^ field5,	% Field5 = 'y'.
> 
> '^' doesn't really make me thing of anything associated with "lookup".
> Would it be possible to use "->",

No, for the reason you give below:

> or would that cause ambiguities with the
> if-then-else syntax?

Yes.

> Or even better, why not use the same symbol as is used for construction?
> 
> 	Field1 = X::field1

Probably we won't be using `::' in record type definitions.
See my other mail.

Using `:', i.e. `Field1 = X:field1', would conflict with the
use of `:' as type qualifier.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- 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