elm-in-elm / compiler / 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 Elm.Data.VarName.VarName, definition : Elm.Data.Type.Type })
    | CustomType ({ parameters : List Elm.Data.VarName.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 Elm.Data.Type.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.

mapBody : (a -> b) -> DeclarationBody a -> DeclarationBody b

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))