[Haskell-beginners] Functor question.
Phillip Pirrip
ppirrip at gmail.com
Sun Nov 15 22:50:05 EST 2009
Hi,
When I define my data as fellow,
data Moo a = Moo a
deriving (Show)
instance Functor Moo where
fmap f (Moo a) = Moo (f a)
GHC gives me no problem. Then I add something,
data (Num a) => Moo a = Moo a
deriving (Show)
instance Functor Moo where
fmap f (Moo a) = Moo (f a)
Now GHC gives me the follow error - see bellow.
What is the reason behind this? What should I do to correct this?
thx,
//
matFun_v2.hs:16:12:
Could not deduce (Num a) from the context ()
arising from a use of `Moo' at matFun_v2.hs:16:12-14
Possible fix:
add (Num a) to the context of the type signature for `fmap'
In the pattern: Moo a
In the definition of `fmap': fmap f (Moo a) = Moo (f a)
In the instance declaration for `Functor Moo'
matFun_v2.hs:16:21:
Could not deduce (Num b) from the context ()
arising from a use of `Moo' at matFun_v2.hs:16:21-29
Possible fix:
add (Num b) to the context of the type signature for `fmap'
In the expression: Moo (f a)
In the definition of `fmap': fmap f (Moo a) = Moo (f a)
In the instance declaration for `Functor Moo'
More information about the Beginners
mailing list