Why is this expression not allowed in Haskell?

I know that Functorthey Applicativeshould be superclasses Monad, but not for historical reasons. However, why is it impossible to declare an Monadinstance Functor? This will have approximately the same effect, but without modifying the existing code. If you are trying to do this, the GHC complains:

instance Functor Monad where
   fmap = liftM

Class `Monad' used as a type
In the instance declaration for `Functor Monad'

Why? There is probably a good reason for this.

+5
source share
2 answers

Your syntax is incorrect. Monadis a type, not a data type. You can write

instance Monad a => Functor a where fmap = liftM

FlexibleInstances ( , T a1 a2 ... an, a1, a2, ... an , ) UndecidableInstances ( [ , ]).

+11

, Monad , . . - . Haskell.

+2

All Articles