newtype-deriving-0.1.4: Instance derivers for newtype wrappers

Safe HaskellNone
LanguageHaskell2010

NewtypeDeriving

Description

This module provides Template Haskell based derivers for typical newtype instances, which the GeneralizedNewtypeDeriving extension refuses to handle.

Here is what it allows you to do:

{-# LANGUAGE UndecidableInstances, TypeFamilies, FlexibleInstances,
             TemplateHaskell, GeneralizedNewtypeDeriving,
             MultiParamTypeClasses #-}

import NewtypeDeriving
import Control.Monad.Base
import Control.Monad.Trans.Control
import Control.Monad.Trans.Class
import Control.Monad.Trans.Either
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.State
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Writer

newtype T m a =
  T (ReaderT Int (StateT Char (WriterT [Int] (EitherT String (MaybeT m)))) a)
  deriving (Functor, Applicative, Monad)

monadTransInstance ''T
monadTransControlInstance ''T
monadBaseTransformerInstance ''T
monadBaseControlTransformerInstance ''T

Synopsis

Documentation

monadTransInstance :: Name -> Q [Dec] Source

Given a name of a newtype wrapper produce an instance of Control.Monad.Trans.Class.MonadTrans.

monadBaseTransformerInstance :: Name -> Q [Dec] Source

Given a name of a newtype wrapper produce an instance of Control.Monad.Base.MonadBase, which is specialised for monad transformers.

monadTransControlInstance :: Name -> Q [Dec] Source

Given a name of a newtype wrapper produce an instance of Control.Monad.Trans.Control.MonadTransControl.

monadBaseControlTransformerInstance :: Name -> Q [Dec] Source

Given a name of a newtype wrapper produce an instance of Control.Monad.Trans.Control.MonadBaseControl, which is specialised for monad transformers.