newtype-th-0.2: A template haskell deriver to create Control.Newtype instances.

Portabilityunportable
MaintainerMichael Sloan (mgsloan@gmail.com)

Control.Newtype.TH

Description

This module provides a template Haskell based mechanism for deriving instances of the Newtype class, defined in Control.Newtype. Example usage:

 newtype CartesianList a = CartesianList [a]
 $(mkNewTypes [''CartesianList])

 instance Monoid (CartesianList a) where
   mempty = pack [[]]
   a `mappend` b = pack [x ++ y | x <- unpack a, y <- unpack b]
 *Main> print $ underF CartesianList (\xs -> [fold xs]) ([[[4],[5],[6]], [[1],[2]], [[0]]])
 [[[4,1,0],[4,2,0],[5,1,0],[5,2,0],[6,1,0],[6,2,0]]]

Synopsis

Documentation

mkNewTypes :: [Name] -> Q [Dec]Source

Derive instances of Newtype, specified as a list of references to newtypes.