0
votes

This code works without the type annotation, but I can't figure out how to annotate the formView function. I also don't know if this is a generic function or what this is actually called?

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)

type Msg = EmailChanged String | PasswordChanged String

formView : String -> msg -> Html Msg
formView label msg = div [] [text (label ++ ": "), input [onInput msg] []]

main = div [] [formView "Email" EmailChanged, formView "Password" PasswordChanged]
1
What type does the type inferencer infer? - Jörg W Mittag
Ok typed it into the elm REPL and it worked, got <function> : String -> (String -> msg) -> Html msg - tableadventure

1 Answers

0
votes

Using the Elm REPL showed me what the type inferencer infers as suggested by @Jörg W Mittag

The correct type annotation as inferred by the type inferencer is:

formView : String -> (String -> msg) -> Html msg