Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Data.Registry.Aeson.TH.Decoder
Synopsis
- makeDecoder :: Name -> ExpQ
- makeDecoderQualified :: Name -> ExpQ
- makeDecoderQualifiedLast :: Name -> ExpQ
- makeDecoderWith :: ThOptions -> Name -> ExpQ
- makeConstructorsDecoder :: ThOptions -> Name -> [Con] -> ExpQ
- makeMatchClause :: ThOptions -> Name -> [Type] -> Con -> MatchQ
- makeErrorClause :: Name -> MatchQ
- applyDecoder :: ThOptions -> Name -> Name -> [(Int, Int)] -> ExpQ
Documentation
makeDecoder :: Name -> ExpQ Source #
Make an Encoder for a given data type Usage: $(makeDecoder ''MyDataType <: otherEncoders)
makeDecoderQualified :: Name -> ExpQ Source #
Make an Encoder for a given data type, where all types names are qualified with their module full name -- MyDataType is defined in X.Y.Z import X.Y.Z qualified $(makeDecoderQualified ''MyDataType <: otherEncoders)
makeDecoderQualifiedLast :: Name -> ExpQ Source #
Make an Encoder for a given data type, where all types names are qualified with their module name -- MyDataType is defined in X.Y.Z import X.Y.Z qualified as Z $(makeDecoderQualifiedLast ''MyDataType <: otherEncoders)
makeDecoderWith :: ThOptions -> Name -> ExpQ Source #
Make a Decoder for a given data type and pass options to specify how names must be qualified Usage: $(makeDecoderWith options ''MyDataType <: otherDecoders)
makeConstructorsDecoder :: ThOptions -> Name -> [Con] -> ExpQ Source #
Make a decoder for a given data type by extracting just enough metadata about the data type in order to be able to parse a Value
For example for the data type:
data T = T1 {f1::Int, f2::Int} | T2 Int Int
we add this function to the registry:
opts d1 d2 d3 -> Decoder $ v -> decodeFromDefinitions opts v $ case ToConstructor T1 [v1, v2]-> T1 $ d1 v1 * d2 v2 ... ToConstructor T2 [v1, v2]-> T2 $ d1 v1 * d3 v2 ... other -> Left ("cannot decode " <> valueToText v)
The case function is the only one which needs to be generated in order to match the exact shape of the constructors to instantiate
makeErrorClause :: Name -> MatchQ Source #
Return an error the json value cannot be decoded with a constructor name and some values