[Haskell-cafe] what exactly does "deriving (Functor, Monad, MonadIO)" do?

Thomas Hartman tphyahoo at gmail.com
Tue May 1 06:05:26 EDT 2007


Thanks Dons.

There's also a short and sweet explanation here.

http://hackage.haskell.org/trac/haskell-prime/wiki/NewtypeDeriving

I am going to try and wrap my head around this, as I am very
interested in solutions for haskell / shell interaction.

Are there are any good examples of code written without this
extension, alongside code condensed by using this extension. That
would be helpful for understanding what's going on.

Thomas.



2007/5/1, Donald Bruce Stewart <dons at cse.unsw.edu.au>:
> tphyahoo:
> > I was trying to follow the reasoning in Don's article on using haskell
> > for shell scripting
> >
> >  http://cgi.cse.unsw.edu.au/~dons/blog/2007/03/10
> >
> > In the source listing at the end we is
> >
> >      newtype Shell a = Shell { runShell :: ErrorT String IO a }
> >        deriving (Functor, Monad, MonadIO)
> >
> > and I don't understand it what "deriving" is doing here, nor have I
> > been able to find documentation on it.
>
> That's 'cunning newtype deriving, my new favourite ghc language
> extension.
>
>     http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#newtype-deriving
>
> We also use it in xmonad,
>
>     newtype X a = X (ReaderT XConf (StateT XState IO) a)
>         deriving (Functor, Monad, MonadIO, MonadState XState, MonadReader XConf)
>
> :-)
>
> -- Don
>


More information about the Haskell-Cafe mailing list