| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Elm.Print.Types
Contents
Description
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
- elmRecordDoc :: ElmRecord -> Doc ann
- elmTypeDoc :: ElmType -> Doc ann
Documentation
prettyShowDefinition :: ElmDefinition -> Text Source #
Pretty shows Elm types.
- See
elmRecordDocfor examples of generatedrecord type alias. - See
elmTypeDocfor examples of generatedtype.
Internal functions
elmRecordDoc :: ElmRecord -> Doc ann Source #
Pretty printer for Elm records:
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]