# [Bug 25191] [XP3.1] Function Conversion Rules for Maps

• From: <bugzilla@jessica.w3.org>
• Date: Wed, 09 Apr 2014 16:00:11 +0000
• Message-ID: <bug-25191-523-n5fNdr9aF1@http.www.w3.org/Bugs/Public/>
```https://www.w3.org/Bugs/Public/show_bug.cgi?id=25191

--- Comment #2 from Michael Kay <mike@saxonica.com> ---
The obvious first cut proposal would be as follows: add to the function
conversion rules the bullet item:

* If the expected type is a MapTest (possibly with an occurrence indicator *,
+, or ?), map coercion is applied to each function in the given value.

Map coercion is a transformation applied to maps during application of the
function conversion rules. Given a map type with a required key type K and a
required value type V, map coercion takes a supplied map and constructs a new
map in which every key is converted to type K, and every value to type V, by
recursive application of the function conversion rules.

However, there are problems with this. The map produced by this process might
have duplicate keys (for example, two different decimal values can be promoted
to the same double value by the function conversion process). Furthermore, and
for similar reasons, it's not easy to create the transformed map as a "virtual"
map supporting efficient lookup operations (this is because the promotion rules
are not readily reversible; if someone wants to look up the key 1e32 and the
original map had decimal keys, you don't know what the original decimal key
would have been.

I think a workable solution to these difficulties is to coerce the values but
not the keys. There is in fact little need to coerce the keys because they have
already been atomized; the only further conversion that can occur is numeric
promotion; and numeric promotion achieves little because we already define the
equality relation across the numeric types (\$M(2) will successfully retrieve an
entry whose key is the double 2e0). So the revised proposal is:

* If the expected type is a MapTest (possibly with an occurrence indicator *,
+, or ?), map coercion is applied to each map in the given value.

Map coercion is a transformation applied to maps during application of the
function conversion rules. Given a map type with a required key type K and a
required value type V, map coercion takes a supplied map and constructs a new
map in which the keys are unchanged, but every associated value is converted to
type V by recursive application of the function conversion rules.

--
You are receiving this mail because:
You are the QA Contact for the bug.
```

Received on Wednesday, 9 April 2014 16:00:13 UTC