elm-bridge-0.8.4: Derive Elm types and Json code from Haskell types, using aeson's options

Safe Haskell | None
Language | Haskell2010

Elm.Derive

Contents

- Options
- Template haskell functions

Description

This module should be used to derive the Elm instance alongside the JSON ones. The prefered usage is to convert statements such as :

    $(deriveJSON defaultOptions{fieldLabelModifier = drop 4, constructorTagModifier = map toLower} ''D)

into:

    $(deriveBoth defaultOptions{fieldLabelModifier = drop 4, constructorTagModifier = map toLower} ''D)

Which will derive both the `aeson` and `elm-bridge` instances at the same time.

Synopsis

- data Options
- data SumEncoding
  - = TaggedObject {
    - tagFieldName :: String
    - contentsFieldName :: String
    }
  - | UntaggedValue
  - | ObjectWithSingleField
  - | TwoElemArray
- defaultOptions :: Options
- defaultOptionsDropLower :: Int -> Options
- deriveElmDef :: Options -> Name -> Q [Dec]
- deriveBoth :: Options -> Name -> Q [Dec]

# Options

data Options #

#### Instances

Instances details

Show Options |
Instance details Defined in Data.Aeson.Types.Internal Methods showsPrec :: Int -> Options -> ShowS Source # show :: Options -> String Source # showList :: [Options] -> ShowS Source #

data SumEncoding #

Constructors

TaggedObject |

Fields

- tagFieldName :: String
- contentsFieldName :: String

UntaggedValue |
ObjectWithSingleField |
TwoElemArray |

#### Instances

Instances details

Show SumEncoding |
Instance details Defined in Data.Aeson.Types.Internal Methods showsPrec :: Int -> SumEncoding -> ShowS Source # show :: SumEncoding -> String Source # showList :: [SumEncoding] -> ShowS Source #
Eq SumEncoding |
Instance details Defined in Data.Aeson.Types.Internal Methods (==) :: SumEncoding -> SumEncoding -> Bool Source # (/=) :: SumEncoding -> SumEncoding -> Bool Source #

defaultOptions :: Options Source #

Note that This default set of options is distinct from that in the `aeson` package.

defaultOptionsDropLower :: Int -> Options Source #

This generates a default set of options. The parameter represents the number of characters that must be dropped from the Haskell field names. The first letter of the field is then converted to lowercase, ie:

    data Foo = Foo { _fooBarQux :: Int }
    $(deriveBoth (defaultOptionsDropLower 4) ''Foo)

Will be encoded as:

    {"barQux"=12}

# Template haskell functions

deriveElmDef :: Options -> Name -> Q [Dec] Source #

Just derive the `elm-bridge` definitions for generating the serialization/deserialization code. It must be kept synchronized with the Haskell code manually.

deriveBoth :: Options -> Name -> Q [Dec] Source #

Equivalent to running both `deriveJSON` and `deriveElmDef` with the same options, so as to ensure the code on the Haskell and Elm size is synchronized.