Safe Haskell | None |
---|---|
Language | Haskell2010 |
Pretty functions for elm
module.
The generated module should contain:
- Type definitions for all ADT
show*
functions for Enum typesread*
functions for Enum typesuniverse*
functions for Enum typesun*
functions for newtypes
Example
The example of Record, Newtype and Enum generated type and functions:
type alias User = { id : Id , name : String , age : Age , status : RequestStatus } type RequestStatus = Approved | Rejected | Reviewing showRequestStatus : RequestStatus -> String showRequestStatus x = case x of Approved -> "Approved" Rejected -> "Rejected" Reviewing -> "Reviewing" readRequestStatus : String -> Maybe RequestStatus readRequestStatus x = case x of "Approved" -> Just Approved "Rejected" -> Just Rejected "Reviewing" -> Just Reviewing _ -> Nothing universeRequestStatus : List RequestStatus universeRequestStatus = [Approved, Rejected, Reviewing] type Id = Id String unId : Id -> String unId (Id x) = x
Synopsis
- prettyShowDefinition :: ElmDefinition -> 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
.
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]