[Haskell-beginners] Bit confused...

mike h mike_k_houghton at yahoo.co.uk
Fri Feb 3 21:47:04 UTC 2017


I have 

----------
import qualified Data.Map as M

type Link a = (a, Int)
data MChain a = Map a   [Link a]  deriving (Show)

-------------------

and want to make a Monoid of MChain. So I have

-------------------
instance Monoid (MChain a) where
   mempty = M.empty 
   mappend = undefined
-------------------

this won’t compile and I need M.empty to be Map a   [Link a] 

The error is
Couldn't match expected type ‘MChain a1’
                 with actual type ‘M.Map k0 a0’
   • In the expression: M.empty :: MChain a
     In an equation for ‘mempty’: mempty = M.empty :: MChain a
     In the instance declaration for ‘Monoid (MChain a)’

This part confuses me "Couldn't match expected type ‘MChain a1 with actual type ‘M.Map k0 a0’ "


How should I proceed. 

Many thanks

Mike






More information about the Beginners mailing list