I wonder if it is possible to implement something like contrib
's Data.SortedMap
where, as an example, the key type could be Key n
and the value type be Value n
where n
is the same Nat
?
For a Map (Key n) (Value n)
(which fails with "No such variable n") some usual functions would then have types like these
Key : Nat -> Type
Value : Nat -> Type
lookup : {n : Nat} -> Key n -> WonderMap Key Value -> Maybe (Value n)
insert : {n : Nat} -> Key n -> Value n -> WonderMap Key Value -> WonderMap Key Value
I tried the following using dependent pairs
MyMap : Type
MyMap = SortedMap (n ** Key n) (n **Value n)
but I think the n
s here are not the same one so it is interpreted like
MyMap = SortedMap (n ** Key n) (x ** Value x)
in other words, the Key and Value types are not "connected" in the way I would like, i.e. a Value n
can only be stored underKey n
and lookup
for a Key n
always returns a Value n
.
And
MyOtherMap : Nat -> Type
MyOtherMap n = SortedMap (Key n) (Value n)
should create a map type indexed by n : Nat
so I could not store Value 1
values under Key 1
keys and Value 7
values under Key 7
keys in the same map.
Is it possible to implement the map type I want where a family of key types are used to store a corresponding family of value types? (Other than having one MyOtherMap
for each n : Nat
and then have all those bundled up in a larger structure, see my answer)