Reputation: 1861
I just began learning Elm and I got stuck with type annotation issue.
This code works:
viewInput : String -> Html msg
viewInput myText =
div [ style [("color","red")] ] [ text myText ]
This one raises a compiler exception:
viewInput : String -> Html msg
viewInput myText =
input [ type' "text", placeholder myText ]
The error is
-- TYPE MISMATCH ------------------------------------------------------ form.elm
The type annotation for `viewInput` does not match its definition.
62| viewInput : String -> Html msg
^^^^^^^^^^^^^^^^^^
The type annotation is saying:
String -> Html a
But I am inferring that the definition has this type:
String -> List (Html a) -> Html a
Detected errors in 1 module.
Upvotes: 0
Views: 265
Reputation: 9008
I think you are just missing some brackets at the end...
Your code should be
viewInput : String -> Html msg
viewInput myText =
input [ type' "text", placeholder myText ] []
This is because the input
function, as div
does, wants in input two lists, one for the attributes, one for the other Html
pieces it contains
Upvotes: 2