<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Ahh! Nice. <div class="">Thanks </div><div class=""><br class=""><div style=""><blockquote type="cite" class=""><div class="">On 20 Oct 2015, at 22:40, Joel Williamson <<a href="mailto:joel.s.williamson@gmail.com" class="">joel.s.williamson@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><p dir="ltr" class="">A type can only have a single instance of a given class. Imagine if this weren't true. The compiler would have to guess which of the instances you meant to use. The solution is to use newtype. That will introduce a different type, allowing separate instances, but is optimised out so it carries no runtime cost.</p>
<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, 20 Oct 2015, 17:24 Mike Houghton <<a href="mailto:mike_k_houghton@yahoo.co.uk" class="">mike_k_houghton@yahoo.co.uk</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Hi,<div class=""><br class=""></div><div class="">I’m looking at a blog post on Monoids and finger trees at <a href="http://apfelmus.nfshost.com/articles/monoid-fingertree.html" target="_blank" class="">http://apfelmus.nfshost.com/articles/monoid-fingertree.html</a></div><div class="">and would appreciate  a bit of advice</div><div class=""><br class=""></div><div class="">I have  </div><div class=""><br class=""></div><div class=""><div class="">type Size = Int</div><div class="">type Priority = Int </div></div><div class=""><br class=""></div><div class=""><div class="">instance Monoid Size where</div><div class="">    mempty  = 0</div><div class="">    mappend = (+)</div></div><div class=""><br class=""></div><div class=""><div class="">instance Monoid Priority where</div><div class="">    mempty  = maxBound</div><div class="">    mappend = min</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">and I get compiler error</div><div class=""><br class=""></div><div class=""><div class="">  Duplicate instance declarations:</div><div class="">      instance Monoid Size</div><div class="">        -- Defined at /Users/mike/haskell/FingerTrees/Ftree.hs:60:10</div><div class="">      instance Monoid Priority</div><div class="">        -- Defined at /Users/mike/haskell/FingerTrees/Ftree.hs:64:10</div></div><div class=""><br class=""></div><div class="">Which I can sort  of understand as Size and Priority are both Int but on the other hand, internally, the monoids  are different.</div><div class=""><br class=""></div><div class="">Is this genuinely incorrect code or is there a language extension to get around this?</div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class="">Mike</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div>_______________________________________________<br class="">
Beginners mailing list<br class="">
<a href="mailto:Beginners@haskell.org" target="_blank" class="">Beginners@haskell.org</a><br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br class="">
</blockquote></div>
_______________________________________________<br class="">Beginners mailing list<br class=""><a href="mailto:Beginners@haskell.org" class="">Beginners@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br class=""></div></blockquote></div><br class=""></div></body></html>