[Haskell-cafe] Announce: EnumMap-0.0.1
John Van Enk
vanenkj at gmail.com
Mon Aug 10 14:50:21 EDT 2009
Allow me to answer my own question:
> EnumMap.insertWithKey f k v m = IntMap.insertWithKey (f . Key . toEnum) (unKey k) v (unEnumMap m)
On Mon, Aug 10, 2009 at 2:32 PM, John Van Enk<vanenkj at gmail.com> wrote:
> I've been trying to implement EnumMap as a wrapper for IntMap. Here's
> the first problem I ran into:
>> IntMap.insertWithKey :: (Key -> a -> a -> a) -> Key -> a -> IntMap a -> IntMap a
> I'd like to translate this to something like:
>> EnumMap.insertWithKey :: Enum k => (Key k -> a -> a -> a) -> Key k -> a -> EnumMap k a -> EnumMap k a
> My initial thought was just to make it a normal wrapper:
>> EnumMap.insertWithKey f k v m = IntMap.insertWithKey f (unKey k) v (unEnumMap m)
> The obvious problem here is the type of `f' expected by the wrapper
> function and the internal function. Either we force the wrapper to
> take a function that takes an Int as the first parameter, or we
> rewrite the logic of insertWithKey to allow us to use the proper (Key
> k) type.
> I don't see an obvious way around this--am I missing something?
> On Sat, Aug 8, 2009 at 4:41 PM, Henning
> Thielemann<lemming at henning-thielemann.de> wrote:
>> On Sat, 8 Aug 2009, John Van Enk wrote:
>>> Hi List,
>>> I've uploaded a first version of EnumMap to hackage.
>>> EnumMap is a generalization of IntMap that constrains the key to Enum
>>> rather than forcing it to be Int. I have no idea what impact this has
>>> on performance, but it still passes all the tests that ship with
>>> IntMap. (My guess is that performance will be similar/identical unless
>>> I've missed something.)
>> Could that be implemented as wrapper around IntMap?
More information about the Haskell-Cafe