[m-dev.] Multi_map: alist interface strange.

Mark Brown dougl at cs.mu.OZ.AU
Tue Aug 20 05:59:09 AEST 2002

On 17-Aug-2002, Douglas Michael Auclair <dauclair at hotmail.com> wrote:
> The problem is this.  If I have received an alist that looks like the 
> following:
> [[3|Datum1], [4|Datum2], [5|Datum3], [4|Datum4], [3|Datum5], [4|Datum6], 
> [5|Datum7], [4|Datum8]]
> I'm then forced to parse and to collect same-key data together ... but 
> that's the purpose a multi-map -- to eliminate this grunt-work from the 
> user.

You can still get the multi_map module to do most of the grunt work;
just call multi_map__set for each member of the list.  I agree, though,
that a library predicate to do this would be useful.

> Similarly, when I receive an alist from another data structure type, 
> I expect a one-to-one mapping between the key and the value, but multi-map 
> transgresses here, too.  As a user of alists, I find these contrary 
> assumptions distressing.

Well, the compiler uses multi_map__to_assoc_list to help it print out the
contents of a multi_map.  In this case, the fact that the values are
collected together for each key is important because that is how the
compiler wants to print the data -- one key followed by possibly many

This is not to say that there can't be two predicates, one with the existing
semantics and one with the semantics you propose.  Implementation would be
trivial; the only real challenge would be to think of good names.  ;-)

> This problem ties in with the bug for multi_map__from_corresponding_lists/3 
> I wrote to this list earlier.

The documentation in the multi_map module isn't very clear, but I am pretty
sure that the current behaviour isn't what was intended.  I'll post a fix for
this one, unless anybody objects soon.


mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au

More information about the developers mailing list