[Haskell-cafe] classes for data structures

Denis Bueno dbueno at gmail.com
Wed Feb 6 10:39:29 EST 2008


On Feb 6, 2008 10:36 AM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
> > type SomethingWithKV k a = KV {getKV :: (k, a)}
> > instance Buildable (Map k a) (SomethingWithKV k a) where
> >   empty = Map.empty
> >   insert s m = uncurry Map.insert (getKV s) m
> >
> > I have done this before -- it's very convenient, and I think makes the
> > code that uses empty and insert more robust, and easier to read.
>
> But why do you want to have the special type SomethingWithKV, but not
> MapSomething ?

Do you mean a map that maps SomethingWithKV to whatever, instead of k to v?

My point is that if you add the functional dependency, you can't write
instances for types which wrap what you're really interested in.  You
have to manually unwrap those types everywhere they interact with a
map.  This is tedious and error-prone.  Being able to write such
instances is useful, I think, though not always clearer in all cases.

-- 
                              Denis


More information about the Haskell-Cafe mailing list