[Haskell-cafe] How to understand such a newtype ?

Felipe Lessa felipe.lessa at gmail.com
Sat Nov 21 21:47:10 EST 2009

On Sat, Nov 21, 2009 at 06:20:40PM -0800, zaxis wrote:
> newtype X a = X (ReaderT XConf (StateT XState IO) a)
> #ifndef __HADDOCK__
>     deriving (Functor, Monad, MonadIO, MonadState XState, MonadReader XConf,
> Typeable)
> #endif
> In `X (ReaderT XConf (StateT XState IO) a)`, X is a type constructor, how to
> understand `(ReaderT XConf (StateT XState IO) a)` ?

Well, “ReaderT XConf (StateT XState IO) a” is *the* type :).
It's a monad that is a Reader of XConf and has a State of XState.
This means you can use, for example,

  ask :: X XConf


  get :: X XState

> And why use `#ifndef __HADDOCK__` ?

Because Haddock used to have difficulties in processing some
directives, like that “deriving (..., MonadState XState, ...)”
which is part of the GeneralizedNewtypeDeriving extension.



More information about the Haskell-Cafe mailing list