I wrote the code:
{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE FlexibleInstances #-} module MonoidApp where class Monoid' a where mempty' :: a mappend' :: a -> a -> a mconcat' :: [a] -> a mconcat' = foldr mappend' mempty' instance Monoid' Int where mempty' :: Int a => a mempty' = 0 mappend' :: Int a => a -> a -> a mappend' a b = (+) a b But it runs into error:
‘Int’ is applied to too many type arguments In the type signature for ‘mempty'’: mempty' :: Int a => a In the instance declaration for ‘Monoid' Int’ Failed, modules loaded: none. Any ideas why?
Intis a type with no parameters, but you've tried to apply it to one. I'm guessing you actually meanmempty' :: Int; mappend' :: Int -> Int -> Int.mempty' :: Int a => aandmappend' :: Int a => a -> a -> a?mappend' 1 2): No instance for (Num a0) arising from a use of ‘it’mappend' (1::Int) (2::Int)