There’s two reasons, as far as I know.
The first reason is, as @bernhard said, that DA.Map
internally uses a data structure that expects key-value pairs to be stored in order, by key. This enables faster lookup and (non-destructive) insert operations. So the keys need to have some notion of “order” in order to make this data structure work (pun intended).
The second reason is that by requiring an order on keys, we can also store and transmit the map in order (e.g. over the ledger API). Because the keys are always in order, there’s no hidden dependence on the way that keys were presented originally. For example,
fromList [("a", 10), ("b", 20)]
and
fromList [("b", 20), ("a", 10)]
have the same map value, because they have the same set of key-value pairs. This sort of normalization leads to code that is easier to test and to predict.
An older version of DA.Map
only required a notion of “equality” on keys, but it introduced a dependence on the order that keys were presented. So the two expressions above actually gave different maps, even though these two maps would otherwise behave the same. So to eliminate this source of unexpected behavior, we strengthened the requirement that keys should be orderable.
So, that’s why we need keys that can be ordered in general.
The documentation you found explains why the Ord
constraint is required for these functions. Like the documentation says, the actual key order that is used in the Daml interpreter is a built-in order. This order agrees with the default Ord
instance that you’d get from “deriving Ord
”. This use of a built-in order ends up being much more efficient than using the Ord
instance directly. So in the end, the Ord
constraint is really only required for type safety!