[Haskell-beginners] duplicate monoids...

Mike Houghton mike_k_houghton at yahoo.co.uk
Tue Oct 20 21:24:10 UTC 2015


I’m looking at a blog post on Monoids and finger trees at http://apfelmus.nfshost.com/articles/monoid-fingertree.html <http://apfelmus.nfshost.com/articles/monoid-fingertree.html>
and would appreciate  a bit of advice

I have  

type Size = Int
type Priority = Int 

instance Monoid Size where
    mempty  = 0
    mappend = (+)

instance Monoid Priority where
    mempty  = maxBound
    mappend = min

and I get compiler error

  Duplicate instance declarations:
      instance Monoid Size
        -- Defined at /Users/mike/haskell/FingerTrees/Ftree.hs:60:10
      instance Monoid Priority
        -- Defined at /Users/mike/haskell/FingerTrees/Ftree.hs:64:10

Which I can sort  of understand as Size and Priority are both Int but on the other hand, internally, the monoids  are different.

Is this genuinely incorrect code or is there a language extension to get around this?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151020/f3cb10b4/attachment.html>

More information about the Beginners mailing list