Haskell has multiple data structures like Map key value
, either using a tree or hash map internally. When using this data structure, it is possible that when doing a lookup, the key will not be present.
In my use case the set of possible keys is finite (technically they are in both Enum
and Ord
) and I am only interested in having a map with all keys present.
How to create a map-like data structure that guarantees all keys are present in the map, i.e. it can have a non-partial function lookup :: Map key value -> key -> value
(possibly with constraints on key
type, Ord
or Hashable
or anything else)? Is there something like this already?
In other words: I want a data structure that can only be queried if all possible keys were inserted. I could use regular Map
with fromMaybe
, but I don't want to have to specify default value – I want to guarantee at type level that default value is never needed.