[mercury-users] Handy Programming tool for Mercury.
Richard A. O'Keefe
ok at atlas.otago.ac.nz
Wed May 12 09:22:42 AEST 1999
For example, piping the following through state2m
* type foo(T)
* a int
* b char readonly
* c string mutable
* d T private
you get
:- pred set_a(foo, int, foo).
:- mode set_a(in, in, out) is det.
I have two comments.
First, when I've done things like this by hand in Prolog, I have
found a *four* argument version
a_varies(Old_Foo, Old_A, New_Foo, New_A)
extraordinarily useful. For example, to increment a
field, you'd do
a_varies(F0, A0, F, A), succ(A0, A)
which is of course bidirectional.
It's not clear to me whether something like this could work
in Mercury, given that whichever mode of a_varies/4 is chosen
you want to fill in the changed field _after_ building the
rest of the record. Of course, if it were split into two
unifications,
(since
a_varies(foo(A0,B,C,D), A0, foo(A,B,C,D), A)
therefore
a_varies(F0, A0, F, A), succ(A0, A)
is equivalent to
F0 = foo(A0,B,C,D), F = foo(A,B,C,D), succ(A0, A)
)
then Mercury _would_ be able to handle it by reordering.
The other comment is that I would have thought that
set_a(New_A_Value, Old_Foo, New_Foo)
would have fitted into DCG notation rather better, so that
one could do
change_all(X) -->
set_a(1),
set_b('c'),
set_c("dee"),
set_d(X).
--------------------------------------------------------------------------
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