Copyright | (c) Song Zhang |
---|---|
License | BSD-style (see the LICENSE file) |
Maintainer | haskell.zhang.song `at` hotmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Data.Derive.TopDown.Standalone
Description
Synopsis
- deriving_ :: Name -> Name -> Q [Dec]
- deriving_with_breaks :: Name -> Name -> [Name] -> Q [Dec]
- derivings :: [Name] -> Name -> Q [Dec]
- derivingss :: [Name] -> [Name] -> Q [Dec]
- deriving_with :: ClassName -> TypeName -> Maybe DerivStrategy -> [TypeName] -> ContextGenderator -> Q [Dec]
- strategy_deriving :: DerivStrategy -> Name -> Name -> Q [Dec]
- strategy_derivings :: DerivStrategy -> [Name] -> Name -> Q [Dec]
- strategy_derivingss :: DerivStrategy -> [Name] -> [Name] -> Q [Dec]
Documentation
Arguments
:: Name | class name |
-> Name | type name |
-> [Name] | type names that stop the deriving process |
-> Q [Dec] |
This is particularly useful with Generic
class.
For the types like Int
, Char
,Ratio
or other types which are not Generic
, there must be a way to stop the generation process on those types.
However, the deriving topdown function will only stop generating Generic
instances on primitive types and Integer
by default, so you do not need to break on them manually.
Another circumtances might be deriving for Typeable
class. Since there is a bug in GHC, isInstance function in TH library is not working on Typeable
, you can manually give the types which are already instances of Typeable
to stop the generation process.
For others cases, there no need to use this function, bacause for a data type A
which is composited by another type, when you manually write an instance declaration for A
, the process will stop on A
automatically since it is already an instance of the type class.
Arguments
:: ClassName | |
-> TypeName | |
-> Maybe DerivStrategy | deriving strategy |
-> [TypeName] | a list of types that breaks the generation process |
-> ContextGenderator | a context generator, |
-> Q [Dec] |
Context generator ca be the following 3
1. genHoleContext: It requires PartialTypeSignatures to make the context of deriving
context a hole
e.g. _ => Cls (D a b)
. This case cannot handle type family
since GHC cannot handle it
2. genInferredContext: It will try to infer the context including cases with type families.
3. genAllFieldsContext: It will put all fields into the context. It may generate like the followings
data List a = Nil | Cons a (List a)
deriving instance (Show a, Show (List a)) => Show (List a)
strategy_deriving :: DerivStrategy -> Name -> Name -> Q [Dec] Source #
strategy_derivings :: DerivStrategy -> [Name] -> Name -> Q [Dec] Source #
strategy_derivingss :: DerivStrategy -> [Name] -> [Name] -> Q [Dec] Source #