Once I have successfully solved an exercise for Functor typeclass:
data ExactlyOne a = ExactlyOne a deriving (Eq, Show)
instance Functor ExactlyOne where
(<$>) ::
(a -> b)
-> ExactlyOne a
-> ExactlyOne b
(<$>) f a = ExactlyOne $ f (runExactlyOne a)
Solving another exercise I needed to define Enum typeclass functions for a custom Odd type.
data Odd = Odd Integer
deriving (Eq, Show)
instance Enum Odd where
-- succ :: Odd -> Odd <-- error
succ (Odd x) = Odd $ x + 2
Now when I try to specify the type signature for a simpler function, ghci gives an error:
Illegal type signature in instance declaration: succ :: Odd -> Odd (Use InstanceSigs to allow this)
It works without it, but I wonder why is this error produced and how to specify the type signature correctly for this function?