<div dir="ltr">Hi Merijn,<div><br></div><div>I have seen unionWith (<>) used many times and it is indeed a useful operation.</div><div>I also do not recall ever relying on the Monoid instance that's defined currently.</div><div>However, I never needed a newtype wrapper.</div><div>Moreover, introducing a newtype just for the sake of the right Monoid instance does not seem to be worth it.<br></div><div><br></div><div>For one I'd want to have all the other useful Map/Set functions (e.g. lookup) defined on the newtype to not have to deal with wrapping/unwrapping newtype. So for the newtype to really be useful, I guess you would have to copy all the functions. I'm guessing this will introduce some maintenance burden.</div><div><br></div><div>Besides you can't really add one newtype for all strict/lazy Map/IntMap. Since `unionWith` is not a typeclass member, you'd have to resort to 4 (or more) newtypes, one for each Map type. And you'd have to copy over all the functions for each newtype...</div><div><br></div><div>I'd be really happy to see default Monoid instances changed, but I too think that's not going to happen (at least anytime soon).</div><div>In the meantime unionWith (<>) seems reasonable enough.</div><div><br></div><div>Can you elaborate on how you benefited from a newtype?<br></div><div>Why unionWith (<>) was not enough?</div><div><br></div><div>Kind regards,</div><div>Nick</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, 24 Mar 2017 at 14:39 Merijn Verstraaten <<a href="mailto:merijn@inconsistent.nl">merijn@inconsistent.nl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Specifically, it's to add (let's use Foo as non-bikeshed name):<br class="gmail_msg">
<br class="gmail_msg">
newtype Foo k v = Foo (Map k v) deriving (...)<br class="gmail_msg">
<br class="gmail_msg">
instance (Ord k, Semigroup v) => Semigroup (Foo k v) where<br class="gmail_msg">
Foo m1 <> Foo m2 = Foo (Map.unionWith (<>) m1 m2)<br class="gmail_msg">
<br class="gmail_msg">
and corresponding Monoid (which would have 'mempty = Foo Map.empty'), deriving all other instances from Map. And the same for IntMap. I don't particularly care whether the Monoid instance should have a Semigroup or Monoid constraint on 'v'.<br class="gmail_msg">
<br class="gmail_msg">
I've personally created this newtype a bunch of times (as have others in #haskell, apparently), but I've never needed/wanted the current Monoid instance. Now I realise that changing the Monoid instance is not happening, so instead I would simply like to add a newtype that has the (to me) more useful Monoid instance.<br class="gmail_msg">
<br class="gmail_msg">
Cheers,<br class="gmail_msg">
Merijn<br class="gmail_msg">
<br class="gmail_msg">
> On 24 Mar 2017, at 11:59, Andreas Abel <<a href="mailto:abela@chalmers.se" class="gmail_msg" target="_blank">abela@chalmers.se</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
> Please make your proposal more specific.<br class="gmail_msg">
> (So that we can tear it apart, haha!)<br class="gmail_msg">
><br class="gmail_msg">
> Seriously, I think it is to vague for starting a discussion.<br class="gmail_msg">
><br class="gmail_msg">
> Best,<br class="gmail_msg">
> Andreas<br class="gmail_msg">
><br class="gmail_msg">
> On 24.03.2017 11:36, Merijn Verstraaten wrote:<br class="gmail_msg">
>> I would like to propose adding a newtype wrapper (with all relevant instances) for Map and IntMap (if I missed any other applicable type in containers, let me know).<br class="gmail_msg">
>><br class="gmail_msg">
>> This newtype should differ in Monoid/Semigroup instance from Map/IntMap by switching:<br class="gmail_msg">
>><br class="gmail_msg">
>> Ord k => Semigroup (Map k v)<br class="gmail_msg">
>> Ord k => Monoid (Map k v)<br class="gmail_msg">
>><br class="gmail_msg">
>> to:<br class="gmail_msg">
>><br class="gmail_msg">
>> (Ord k, Semigroup v) => Semigroup (Map k v)<br class="gmail_msg">
>> (Ord k, Monoid v) => Monoid (Map k v) or (Ord k, Semigroup v) => Monoid (Map k v)<br class="gmail_msg">
>><br class="gmail_msg">
>> Any opinions on the overall idea? Opinions on which Monoid instance? Bikeshed for the newtype names?<br class="gmail_msg">
>><br class="gmail_msg">
>> Cheers,<br class="gmail_msg">
>> Merijn<br class="gmail_msg">
>><br class="gmail_msg">
>><br class="gmail_msg">
>><br class="gmail_msg">
>> _______________________________________________<br class="gmail_msg">
>> Libraries mailing list<br class="gmail_msg">
>> <a href="mailto:Libraries@haskell.org" class="gmail_msg" target="_blank">Libraries@haskell.org</a><br class="gmail_msg">
>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br class="gmail_msg">
>><br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> --<br class="gmail_msg">
> Andreas Abel <>< Du bist der geliebte Mensch.<br class="gmail_msg">
><br class="gmail_msg">
> Department of Computer Science and Engineering<br class="gmail_msg">
> Chalmers and Gothenburg University, Sweden<br class="gmail_msg">
><br class="gmail_msg">
> <a href="mailto:andreas.abel@gu.se" class="gmail_msg" target="_blank">andreas.abel@gu.se</a><br class="gmail_msg">
> <a href="http://www.cse.chalmers.se/~abela/" rel="noreferrer" class="gmail_msg" target="_blank">http://www.cse.chalmers.se/~abela/</a><br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Libraries mailing list<br class="gmail_msg">
<a href="mailto:Libraries@haskell.org" class="gmail_msg" target="_blank">Libraries@haskell.org</a><br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br class="gmail_msg">
</blockquote></div>