language-elm-0.1.0.2: Generate elm code

Safe HaskellTrustworthy
LanguageHaskell2010

Elm

Contents

Synopsis

Expressions

bool :: Bool -> Expr Source #

A boolean literal

string :: String -> Expr Source #

A string literal

int :: Int -> Expr Source #

An integer literal

float :: Float -> Expr Source #

A float literal

under :: Expr Source #

An _ literal

var :: String -> Expr Source #

A variable

app :: [Expr] -> Expr Source #

Function application

>>> genStr (app [var "a", var "b", var "c"])
"a b c"

list :: [Expr] -> Expr Source #

A list literal

op :: String -> Expr -> Expr -> Expr Source #

Apply an operator to two sub expressions

>>> genStr (op "+" (int 5) (int 6))
"5 + 6"

let_ :: Expr -> [(Expr, Expr)] -> Expr Source #

A let...in block

>>> putStrLn $ genStr (let_ (var "a") [(var "a", int 5)])
let
    a = 5
in
    a

case_ :: Expr -> [(Expr, Expr)] -> Expr Source #

A case...of block

>>> :{
 putStrLn $ genStr
     (case_ (var "m")
         [ (app [var "Just", var "x"], var "x")
         , (var "Nothing", var "default")
         ])
:}
case m of
    Just x ->
        x

    Nothing ->
        default

parens :: Expr -> Expr Source #

Wrap a sub expression in parens

Types

tvar :: String -> Type Source #

A type or type variable

>>> genStr (tvar "Nothing")
"Nothing"
>>> genStr (tvar "a")
"a"

tparam :: String -> Type -> Type Source #

A type with a single paramater

>>> genStr (tparam "Just" (tvar "a"))
"Just a"

tparams :: String -> [Type] -> Type Source #

A type with multiple paramaters

>>> genStr (tparams "Result" [tvar "String", tvar "Int"])
"Result String Int"

tapp :: [Type] -> Type Source #

Type application

>>> genStr (tapp [tvar "a", tvar "b", tvar "c"])
"a -> b -> c"

tunit :: Type Source #

A zero item tuple type

>>> genStr tunit
"()"

ttuple :: [Type] -> Type Source #

A multiple item tuple

>>> genStr (ttuple [tvar "a", tvar "b"])
"(a, b)"

trecord :: [(String, Type)] -> Type Source #

A record type

>>> genStr (trecord [("a", tvar "Int"), ("b", tvar "String")])
"{ a : Int, b : String }"

trecordParam :: String -> [(String, Type)] -> Type Source #

A paramaterized record type

>>> genStr (trecordParam "a" [("b", tvar "Int")])
"{ a | b : Int }"

Declerations

decVariable Source #

Arguments

:: String

The variable name

-> Type

The variable's type

-> Expr

The variable's value

-> Dec 

Declare a variable

decFunction Source #

Arguments

:: String

The function name

-> Type

The function's type

-> [Expr]

The fuction's paramaters

-> Expr

The function's value

-> Dec 

Declare a function

decType Source #

Arguments

:: String

The type name

-> [String]

The type's type paramaters

-> [(String, [Type])]

The type's constructors

-> Dec 

Declare a type

decTypeAlias Source #

Arguments

:: String

The type alias' name

-> [String]

The type alias's type paramaters

-> Type

The type alias's type

-> Dec 

Declare a type alias

Imports

select :: String -> ImportItem Source #

Import an item

subSelect :: String -> [String] -> ImportItem Source #

Import an item and some constructors

subSelectEvery :: String -> ImportItem Source #

Import an item and all constructors

importSome :: [ImportItem] -> ImportExpr Source #

Import all exports of a module

importEvery :: ImportExpr Source #

Import some exports of a module

import_ Source #

Arguments

:: String

The name of the module to import

-> Maybe String

A possible alias to import the module as

-> Maybe ImportExpr

A possible set of items to expose

-> Import 

Import a module

Module

module_ Source #

Arguments

:: String

The module name

-> ImportExpr

The module exports

-> [Import]

The module imports

-> [Dec]

The module decleration

-> Module 

Generate a full module

Generation

renderModule :: Module -> (String, GenError) Source #

Render a module, returning possible errors or warnings

render :: Module -> String Source #

Render a module, throwing an error if there is an error or warnings