derive-monoid-0.0.0: derive Semigroup/Monoid/IsList

Safe HaskellNone
LanguageHaskell2010

Derive.List.Extra

Synopsis

Documentation

saturateT :: Name -> Q Type Source

saturates a type constructor with type variables. outputs a Type of kind *.

>>> :set -XTemplateHaskell
>>> import Language.Haskell.TH
>>> $(printQ (saturateT ''Bool))
ConT GHC.Types.Bool 
>>> $(printQ (saturateT ''[]))
AppT (ConT GHC.Types.[]) (VarT a)
>>> $(printQ (saturateT ''Either))
AppT (AppT (ConT Data.Either.Either) (VarT a)) (VarT b)
  • - >>> $(printQ (saturateT_ 'False))
  • - Exception when trying to run compile-time code:
  • - the name {{GHC.Types.False}} has no arity (maybe it's been given to some macro that expects a Type?)

output is deterministic.

alphabeticalVariables :: [String] Source

>>> take 3 alphabeticalVariables
["a","b","c"]

getArityT :: Name -> Q (Maybe Int) Source

get the arity of a (type) name.

>>> :set -XTemplateHaskell
>>> import Language.Haskell.TH
>>> $(printQ (getArityT ''Bool))
Just 0
>>> $(printQ (getArityT 'False))
Nothing
>>> $(printQ (getArityT ''Either))
Just 2

getArityI :: Info -> Maybe Int Source

get the arity of a type constructor or a primitive type constructor, by name.

getArityD :: Dec -> Maybe Int Source

get the arity of a data or a newtype.

TODO saturate type synonym0

printQ :: Show a => Q a -> Q Exp Source

show the result of a Template Haskell action, in IO.

>>> :set -XTemplateHaskell
>>> import Language.Haskell.TH
>>> $(printQ $ reify ''Bool)
TyConI (DataD [] GHC.Types.Bool [] [NormalC GHC.Types.False [],NormalC GHC.Types.True []] [])

works around "Template Haskell error: Can't do reify in the IO monad", which prevents them from being printed directly.

see stackoverflow