FW: [mercury-users] Records

Peter Schachte schachte at cs.mu.OZ.AU
Wed Nov 10 22:27:52 AEDT 1999


On Wed, Nov 10, 1999 at 01:07:18PM +1300, Richard A. O'Keefe wrote:
> 	I still
> 	don't want to have to define all the combinations of setters.
> 
> Let me give an example that shows why being _able_ to define
> combinations is important.

I understand why you should to be able to.  I assume you see why I
don't want to be forced to.

> 	But what happens when you're setting 3 members, and
> 	there are setters defined for each individual field and for each
> 	combination of two?  The compiler could choose any of the 3 pairs
> 	together with the remaining individual setter, and could apply these
> 	two setters in either order, for 6 possible choices.  Which one do you
> 	choose?
> 	
> There's the answer:  YOU choose, not the compiler.  It's an ambiguity.
> If the compiler tells you
> 	R with {A=X, B=Y, C=Z}
> is ambiguous between uses of A:=, B:=, C:=, AB:=, BC:=, AC:=,
> then YOU choose which one you mean and write it that way:
> 	R with {A=X} with {B=Y,C=Z}

It's all getting rather complex.  I think it's just as easy for the
user, and much simpler for the language, to provide setters for tuples
of fields:

	:- func 'date:='(date, pair(pair(int,int),int)) = date.
	'date:='(date(_,_,_,Weekday),Y-M-D) = date(Y,M,D,Weekday).

then you could write

	Newdate = Date ^ date := 1999-11-10.

Then whatever integrity constraints are attached to the type kick in.
Since intermediate structures are never constructed, this works just
fine.  (This would be a lot nicer if Mercury had a decent syntax for
tuples, but let's just worry about one syntax hack at a time.)

-- 
Peter Schachte                     [A computer is] like an Old Testament
mailto:schachte at cs.mu.OZ.AU        god, with a lot of rules and no mercy.
http://www.cs.mu.oz.au/~schachte/      -- Joseph Campbell 
PGP: finger schachte at 128.250.37.3  
--------------------------------------------------------------------------
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