From LYAH I understand that the do
notation is just syntactic sugar for monadic style; and from the wikibook I read more or less the same; so my understanding is that there can't be any do
notation if there's no Monad
instance.
Yet I read this definition of the Functor
instance of the IO
type ctor.
instance Functor IO where
fmap f action = do
result <- action
return (f result)
which is just syntactic sugar for the following, isn't it?
instance Functor IO where
fmap f action = action >>= return . f
which implies the underling assumption the IO
is instance of Monad
first; and this come against that fact that every Monad
is a Functor
and not the other way around.
In fact, I had absorbed that a Monad
is "something more than" an Applicative
, which is in turn "something more than" a Functor
, which goes together with Applicative
's definition enforcing the Functor
constraint on its instances (and Monad
's definition ideally requiring that its instances are Applicative
s, as in don't make it a Monad
if it's not an Applicative
).
In other words, the code above makes me think that there would be no way to write the Functor
instance for IO
, if IO
was not a Monad
in the first place.
And now that I think about it, maybe this is just like saying that IO
was created as a full-fledged Monad
, and the instance above was later made just for completeness and mathematical consistency.
But I'm confused, and so I seek for help here.