[Haskell-cafe] Custome monoid mappend on HashMap and HashSet values

Alexander V Vershilov alexander.vershilov at gmail.com
Sat May 10 06:07:01 UTC 2014

Hi, John.

You can always use newtype wrapper if you need to overload existing method

newtype MyHashMap a b = MyHashMap { unMy :: HashMap a b}

instance Monoid (MyHasMap a b) where
  mempty = MyHasMap mempty
  mappend a b = your_overloaded_function

Then just wrap and unwrap your data to do a custom mappend, also you can
write a wrapper function, in case if you'll restrict types then it may work
only for the types you need:

(<~>) :: HashMap Int (HashMap Int Int) -> HashMap Int (HashMap Int Int) ->
HashMap Int (HashMap Int Int)
a <~> b = unMy $ (<>) `on` MyHashMap a b

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140510/a51e23be/attachment.html>

More information about the Haskell-Cafe mailing list