[Haskell-cafe] Re: Harder than you'd think
apfelmus at quantentunnel.de
Sun Jun 13 13:03:46 EDT 2010
Marc Weber wrote:
> Andrew Coppin wrote:
>> What I ended up writing is this:
>> lookup :: KeyID -> Key -> Container -> Maybe Value
>> Does anybody have a less-insane way of doing this?
> type MyMap = Map (KeyID, Key) Value
> Don't use multiple keys. Put the keys into a tuple and use that as key.
Actually, it's a disjoint sum type:
data a :+: b = Inl a | Inr b -- also known as Either
type DB3 e k1 k2 k2 = D1 e (k1 :+: k2 :+: k3)
Hm, that's not quite right either because every e has multiple keys.
The following should work, however:
type DB3 e k1 k2 k2 = D1 e k1 :*: DB1 e k2 :*: DB2 e k3
lookup :: (k1 :+: k2 :+: k3) -> DB3 e k1 k2 k3 -> Maybe e
In any case, I recommend using a special key type for combining keys
anyway, as explained here
More information about the Haskell-Cafe