[m-dev.] Is this a bug?
Ralph Becket
rafe at csse.unimelb.edu.au
Mon Jun 18 13:55:27 AEST 2007
Ralph Becket, Monday, 18 June 2007:
> I'm trying to use field update syntax to update a map of maps, but it
> isn't working:
>
> ::: map_map_update_test.m :::
>
> :- module map_map_update_test.
> :- interface.
> :- import_module io.
>
> :- pred main(io::di, io::uo) is det.
>
> :- implementation.
> :- import_module map.
>
> main(!IO) :-
> A0 = map.init,
> A = A0 ^ elem(42) ^ elem(99) := 123,
> io.write_int(A ^ det_elem(42) ^ det_elem(99), !IO),
> io.nl(!IO).
>
> ::: end of map_map_update_test.m :::
Ah, I've understood the problem:
A = A0 ^ elem(42) ^ elem(99) := 123
expands according to the following rule in the reference manual
transform(Term ^ Field(Arg1, ...) := FieldValue) =
'Field :='(Arg1, ..., Term, FieldValue)).
transform(Term0 ^ Field(Arg1, ...) ^ Rest := FieldValue) = Term :-
OldFieldValue = Field(Arg1, ..., Term0),
NewFieldValue = transform(OldFieldValue ^ Rest := FieldValue),
Term = 'Field :='(Arg1, ..., Term0, NewFieldValue).
The OldFieldValue uses the `elem' field access function which is
semidet.
This is somewhat counterintuitive.
-- Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions: mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the developers
mailing list