[Haskell-cafe] Re: Harder than you'd think

Heinrich Apfelmus 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: 
>> http://www.hpaste.org/fastcgi/hpaste.fcgi/view?id=25782
>>   lookup :: KeyID -> Key -> Container -> Maybe Value
> 
>> Does anybody have a less-insane way of doing this?
> 
> Sure: 
> 
>   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

  http://article.gmane.org/gmane.comp.lang.haskell.cafe/23648



Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



More information about the Haskell-Cafe mailing list