I read (for example here and here) that all of the base monads
(Mabye
, Error
, ...) are derived from their corresponding monad transformers
(MaybeT
, ErrorT
, ...) using the identity monad Identity
. An example would be:
type Maybe a = MaybeT Identity a
But that of course doesn't result in a constructor for Maybe a
.
And in the sources MaybeT
is defined as newtype MaybeT m a = MaybeT (m (Maybe a))
.
Am I missing something important?
How could one derive a base monad using the corresponding monad transformer and the identitiy monad resulting in a concrete
constructor that can be matched against?
Maybe
is defined inbase
, monad transformers generally come from a library liketransformers
ormtl
. TheError
monad also comes from a library, along withState
,Reader
, andWriter
. In this case,Maybe
andMaybeT
are the odd ones out. – bheklilrMaybeT Identity a
is equivalent toMaybe a
-- it reduces to a newtypeMaybeT
aroundIdentity (Maybe a)
-- but it's not literally the same thing, partially becauseMaybe
is treated as a data structure first and a monad second. – Louis Wassermantype Maybe a = MaybeT Identity a
." No, but a correct example would betype State s = StateT s Identity
. – Daniel Wagner