Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elm Language What do the Multiple Types in a row (without the arrow) in a signature mean?

Tags:

elm

In the Elm language, I'm having a hard time explaining my question... In these snippets in elm: I understand the signature in something like

update : Msg -> Model -> Model

where the parameters / output is separated by arrows, but how do I read / grok things like:

Sub Msg
Program Never Model Msg

In:

main : Program Never Model Msg
main =
    program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }

subscriptions : Model -> Sub Msg
subscriptions model =
    Sub.none
like image 970
banncee Avatar asked Nov 17 '16 21:11

banncee


1 Answers

In a type signature, parameter types are separated by ->, with the last type being the return value.

If there are no -> symbols, then it means it is a value of that type. In your main example, the type of main is Program Never Model Msg. It has no arrows, so it takes no parameters.

Now, each parameter and the return value in the type annotation may have several things separated by spaces, as in your main example. The leftmost is the type, followed by type parameters separated by spaces.

Program Never Model Msg
   |      |     |    |
   |      ------|-----
 type    type parameters

A type parameter is similar to Generics in a language like C#. The equivalent syntax in C# would be:

void Program<Never, Model, Msg>()

C# doesn't directly correlate because it has a different way of constraining generic type parameters, but the general idea holds.

The Elm guide doesn't currently have a great deal of info, but here is the section talking about types.

like image 102
Chad Gilbert Avatar answered Jan 04 '23 09:01

Chad Gilbert