[mercury-users] Field updates and state variables

Peter Hawkins hawkinsp at cs.stanford.edu
Mon Jul 3 05:28:06 AEST 2006


Hi...

I find myself writing code like this a lot:

:- type my_state ---> my_state(my_map :: map(int, int)).

:- pred foo(my_state::in, my_state::out) is det.
foo(!S) :-
...
!:S = !.S ^ my_map := map.insert(!.S ^ my_map, Key, Value)
...

Wouldn't it be nice if I could write the field update as:
map.insert(Key, Value, !S ^ my_map)
and have the compiler expand it to the code above? I'd like that a lot.

Cheers,
Peter

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