What's wrong instance Functor Int where
instance Functor Int where
fmap f a = f a
Expected kind ...
I can't make monad int , applicative int, functor int
What is so interesting about Maybe a, [a], Either e a, IO a? The type takes an additional parameter. That is, Maybe on its own isn't a type. You have to use another type e.g. Int to actually get a type: Maybe Int.
Let's have a look at Functor's definition:
class Functor f where
fmap :: (a -> b) -> f a -> f b
-- ^^^ ^^^
Whatever you use for f must be able to use a type. And Int Int or Int () is not a type, because Int is already at kind *. You cannot construct another type by applying Int on something else.
Maybe on the other hand is of kind * -> *. It takes a type (e.g. Double) and returns a type, Maybe Double:
-- using pseudo kind-signatures
Maybe :: * -> *
Double :: *
Maybe Double :: *
All that because our f takes an a in the signature of fmap.
So no. You cannot make any regular type (of kind *) an instance of Functor.
Functor,ApplicativeandMonadis that the type you give it actually has to have kind* -> *- it needs to be expecting a type variable. In vanilla Haskell, kinds are simply inferred. Looking at theFunctorclass, you'll notice thatfis always applied to a type variable. That let's the compiler infer thatfhas kind* -> *. That means things likeMaybe, lists,IO, etc. NOTBool,Int,(), etc. - AlecIdentityhas functor/applicative/monad instances similar to this. For example,runIdentity (fmap (+ 5) (pure 2 :: Identity Int)) == 7. - Jon Purdy