2

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?

8
  • 1
    The error message is pretty clear: Int is a type with no parameters, but you've tried to apply it to one. I'm guessing you actually mean mempty' :: Int; mappend' :: Int -> Int -> Int. Commented Mar 28, 2016 at 22:15
  • What if you leave out lines mempty' :: Int a => a and mappend' :: Int a => a -> a -> a? Commented Mar 28, 2016 at 22:17
  • @J.J.Hakala Then I cannot use the function with parameter (mappend' 1 2): No instance for (Num a0) arising from a use of ‘it’ Commented Mar 28, 2016 at 22:26
  • I need to a type every time to make it work: mappend' (1::Int) (2::Int) Commented Mar 28, 2016 at 22:35
  • 3
    Don't change your question in a way that doesn't include your original problem. If you have additional information add an update section, if you have new questions open a separate question. Commented Mar 29, 2016 at 0:17

1 Answer 1

3

It should be:

instance Monoid' Int where mempty' :: Int mempty' = 0 mappend' :: Int -> Int -> Int mappend' a b = (+) a b 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.