I have the following model and update function:
type alias Model =
{ people: List String
, entry: String
}
model : Model
model =
{ people = ["foo2"]
, entry = "foo"
}
update : Msg -> Model -> Model
update msg model =
case msg of
AddNewParticipant ->
{ model | people = List.append model.people model.entry }
On line 19, we see:
{ model | people = List.append model.people model.entry }
Elm complier gives the error:
-- TYPE MISMATCH ------------------------------------------------------- app.elm
The type annotation for `update` does not match its definition.
41| update : Msg -> Model -> Model
^^^^^^^^^^^^^^^^^^^^^
The type annotation is saying:
Msg -> { ..., entry : String } -> { ..., entry : String }
But I am inferring that the definition has this type:
Msg -> { ..., entry : List String } -> { ..., entry : List String }
The real problem is that I'm passing a String to the List.append function.
{ model | people = List.append model.people model.entry }
should be
{ model | people = List.append model.people [model.entry] }
So why isn't the compiler telling me that the problem is with List.append?
Telling me the problem is with update
is confusing.