elm-in-elm/compiler/1.0.0

NOTE: the latest version is 1.0.1

Elm.Data.Declaration

Top-level declaration, be it a function, constant or a type definition.

type alias Declaration expr =
{ module_ : String
, name : String
, body : DeclarationBody expr
}
type DeclarationBody expr
= Value expr
| TypeAlias
{ parameters : List VarName
, definition : Type
}
| CustomType
{ parameters : List VarName
, constructors : List Constructor
}
 x = 1
 --> Value (Int 1)


 type alias X = Int
 --> TypeAlias [] Int


 type alias X a = Maybe a
 --> TypeAlias ["a"] (Maybe (Var 0))
type alias Constructor =
{ name : String
, arguments : List TypeArgument
}

Constructor of a custom type.

 type Foo = Bar
 --> CustomType [] [Constructor "Bar" []]


 type Foo a = Bar
 --> CustomType [] [Constructor "Bar" []]


 type Foo a = Bar a
 --> CustomType ["a"] [Constructor "Bar" ["a"]]


 type Foo = Bar | Baz
 --> CustomType []
        [ Constructor "Bar" []
        , Constructor "Baz" []
        ]
map : (a -> b) -> Declaration a -> Declaration b

Apply a function to the expression inside the declaration.

Apply a function to the expression inside the declaration body.

combine : DeclarationBody (Result err a) -> Result err (DeclarationBody a)

Switch the Result and the expression inside the declaration body. Similar to Result.Extra.combine.

combine (Value (Ok (Int 5)))
--> Ok (Value (Int 5))