Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines prettyprinter for ElmDefinition
type.
and exports the function to represent it in the convenient way.
Synopsis
- prettyShowDefinition :: ElmDefinition -> Text
- prettyShowEncoder :: ElmDefinition -> Text
- prettyShowDecoder :: ElmDefinition -> Text
- encodeMaybe :: Text
- encodeEither :: Text
- encodePair :: Text
- decodeEnum :: Text
- decodeChar :: Text
- decodeEither :: Text
- decodePair :: Text
- elmAliasDoc :: ElmAlias -> Doc ann
- elmTypeDoc :: ElmType -> Doc ann
Documentation
prettyShowDefinition :: ElmDefinition -> Text Source #
Pretty shows Elm types.
- See
elmAliasDoc
for examples of generatedtype alias
. - See
elmTypeDoc
for examples of generatedtype
.
prettyShowEncoder :: ElmDefinition -> Text Source #
Returns the encoder for the given type.
TODO
+-------------------+------------------+-----------------+---------------------+
| Haskell Type | Eml Type | Encoder | JSON |
+===================+==================+=================+=====================+
| Int
| Int
| standard encoder | |
+-------------------+------------------+------------------+--------------------+
prettyShowDecoder :: ElmDefinition -> Text Source #
- *Sum Types:**
Haskell type
type User = Foo | Bar String Int
Encoded JSON on Haskell side
[ { "tag" : Foo } , { "tag" : Bar , "contents" : ["asd", 42, "qwerty"] } ]
Elm decoder
userDecoder : Decoder User userDecoder = let decide : String -> Decoder User decide x = case x of Foo -> D.succeed Foo Bar -> D.field "contents" <| D.map2 Bar (D.index 0 D.string) (D.index 1 D.int) x -> D.fail <| "There is no constructor for User type:" ++ x in D.andThen decide (D.field "tag" D.string)
Standard missing encoders
encodeMaybe :: Text Source #
encodeEither :: Text Source #
encodePair :: Text Source #
Standard missing decoders
decodeEnum :: Text Source #
decodeChar :: Text Source #
decodeEither :: Text Source #
decodePair :: Text Source #
Internal functions
elmAliasDoc :: ElmAlias -> Doc ann Source #
Pretty printer for Elm aliases:
type alias User = { userHeh : String , userMeh : Int }
elmTypeDoc :: ElmType -> Doc ann Source #
Pretty printer for Elm types with one or more constructors:
type Status a = Foo String Int | Bar a | Baz
If the type is a newtype then additionally unTYPENAME
function is generated:
type Id a = Id String unId : Id a -> String unId (Id x) = x
If the type is Enum this function will add enum specific functions:
type Status = Approved | Yoyoyo | Wow showStatus : Status -> String showStatus x = case x of Approved -> Approved Yoyoyo -> Yoyoyo Wow -> Wow readStatus : String -> Maybe Status readStatus x = case x of Approved -> Just Approved Yoyoyo -> Just Yoyoyo Wow -> Just Wow _ -> Nothing universeStatus : List Status universeStatus = [Approved, Yoyoyo, Wow]