[mercury-users] Records
Robert Ernst Johann JESCHOFNIK
rejj at cat.cs.mu.OZ.AU
Tue Nov 2 23:26:22 AEDT 1999
On Tue, 2 Nov 1999, Simon Taylor wrote:
Hello.
> :- 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.
> % 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 "->", or would that cause ambiguities with the
if-then-else syntax?
Field1 = X->field1
does seem a tad `better', though.
Or even better, why not use the same symbol as is used for construction?
Field1 = X::field1
> % field update.
> X1 = X0 ^ field1 := 2, % X1 = t(2, "abc", t2(1.5, 'y')).
> X = X1 ^ field3 ^ field5 := 'z'.
> % X2 = t(2, "abc", t2(1.5, 'z')).
Perhaps here would be a good place for the '->'..
X1 = X0::field1 -> 2,
X = X1::field3::field5 -> 'z'.
> % DCG example:
> :- pred bar(t::in, t::out) is det.
> bar -->
> Field1 := ^ field1,
> Field5 := ^ field3 ^ field5,
>
> ^ field1 := 2,
> ^ field3 ^ field5 := 'z'.
bar -->
Field1 -> ::field1,
Field5 -> ::field3::field5,
::field1 -> 2,
::field3::field5 -> 'z'.
I think either way it looks pretty ugly in a DCG.. but I can't really
think of any way to remedy this.
Ah well, just my proverbial two cents worth.
Rob
--------------------------------------------------------------------------
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