<div>Hi all,</div><div><br></div>Currently Data.Map has a Monoid instance, but it&#39;s rather lossy and not as general as it could be:<div><pre><span class="hs-keyword" style="color:blue">instance</span> <span class="hs-layout" style="color:red">(</span><span class="hs-conid">Ord</span> <span class="hs-varid">k</span><span class="hs-layout" style="color:red">)</span> <span class="hs-keyglyph" style="color:red">=&gt;</span> <span class="hs-conid">Monoid</span> <span class="hs-layout" style="color:red">(</span><span class="hs-conid">Map</span> <span class="hs-varid">k</span> <span class="hs-varid">v</span><span class="hs-layout" style="color:red">)</span> <span class="hs-keyword" style="color:blue">where</span>
<a name="line-231"></a>    <span class="hs-varid">mempty</span>  <span class="hs-keyglyph" style="color:red">=</span> <span class="hs-varid">empty</span>
<a name="line-232"></a>    <span class="hs-varid">mappend</span> <span class="hs-keyglyph" style="color:red">=</span> <span class="hs-varid">union</span>
<a name="line-233"></a>    <span class="hs-varid">mconcat</span> <span class="hs-keyglyph" style="color:red">=</span> <span class="hs-varid">unions</span></pre><pre><span class="hs-varid"><br></span></pre><pre><font face="arial"><span style="white-space:normal">The instance would be much nicer if it required a Monoid on v and used unionWith mappend instead of just union. The current behavior could be emulated by using First/Last as the Monoid (or ideally a semigroup, but that&#39;s or another discussion), but other more interesting Monoid instances could also be used for the values.</span></font></pre>
<pre><font face="arial"><span style="white-space:normal">I realize that changing instances could break code, but I&#39;d be curious to see how many people even use the current monoid instance. Does anyone have any system for testing hypotheses like this (by typechecking a large randomized chunk of hackage or something)?</span></font></pre>
<pre><font face="arial"><span style="white-space:normal">It looks like the idea has been around for at least five years: <a href="http://hackage.haskell.org/trac/ghc/ticket/1460">http://hackage.haskell.org/trac/ghc/ticket/1460</a> but the proposal was abandoned, so I wanted to see if I could get people to start talking about it again.</span></font></pre>
<pre><font face="arial"><span style="white-space:normal">Thanks,</span></font></pre><pre><font face="arial"><span style="white-space:normal">Dan</span></font></pre></div>