barbara
barbara

Reputation: 3201

Haskell Type issue

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?

Upvotes: 2

Views: 66

Answers (1)

Bolo
Bolo

Reputation: 11690

It should be:

instance Monoid' Int where
    mempty' :: Int
    mempty' = 0

    mappend' :: Int -> Int -> Int
    mappend' a b = (+) a b

Upvotes: 3

Related Questions