Safe Haskell | None |
---|---|
Language | Haskell2010 |
FIXME: doesn't handle multiparameter classes like Integral and Vector
FIXME: should this be separated out into another lib when finished?
- deriveHierarchy :: Name -> [Name] -> Q [Dec]
- deriveHierarchyFiltered :: Name -> [Name] -> [Name] -> Q [Dec]
- deriveSingleInstance :: Name -> Name -> Q [Dec]
- deriveTypefamilies :: [Name] -> Name -> Q [Dec]
- mkMutableNewtype :: Name -> Q [Dec]
- listSuperClasses :: Name -> Q [Name]
- fromPreludeEq :: Q Type -> Q [Dec]
- type BasicType t = (Show t, Read t, Arbitrary t, NFData t)
- helper_liftM :: Monad m => (a -> b) -> m a -> m b
- helper_id :: a -> a
template haskell functions
deriveHierarchy :: Name -> [Name] -> Q [Dec] Source
This is the main TH function to call when deriving classes for a newtype. You only need to list the final classes in the hierarchy that are supposed to be derived. All the intermediate classes will be derived automatically.
deriveHierarchyFiltered :: Name -> [Name] -> [Name] -> Q [Dec] Source
Like "deriveHierarchy" except classes in the second list will not be derived.
deriveSingleInstance :: Name -> Name -> Q [Dec] Source
Given a single newtype and single class, constructs newtype instances
deriveTypefamilies :: [Name] -> Name -> Q [Dec] Source
creates the instance:
type instance Scalar (Newtype s) = Scalar s
mkMutableNewtype :: Name -> Q [Dec] Source
listSuperClasses :: Name -> Q [Name] Source
List all the superclasses of a one parameter class. This does not include: * constraints involving types other than the parameter (e.g. made with type families). * type synonyms (although these will get substituted in the recursion)
For example, convert ''Group into [''Semigroup, ''Monoid, ''Cancellative, ''Group]
compatibility functions
fromPreludeEq :: Q Type -> Q [Dec] Source
Generate an Eq_ instance from the Prelude's Eq instance. This requires that Logic t = Bool, so we also generate this type instance.
helpers
type BasicType t = (Show t, Read t, Arbitrary t, NFData t) Source
This class provides an artificial hierarchy that defines all the classes that a "well behaved" data type should implement. All newtypes will derive them automatically.
helper_liftM :: Monad m => (a -> b) -> m a -> m b Source
We need to export this function for deriving of Monadic functions to work