Greetings!
I have trouble compiling the following code. It’s available on Ellie: https://ellie-app.com/7SS2VZ8b24Pa1
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
type alias Model =
{ count : Int }
initialModel : Model
initialModel =
{ count = 0 }
type Msg i
= Increment {i | count : Int}
| Decrement
update : Msg i -> Model -> Model
update msg model =
case msg of
Increment m ->
{ model | count = m.count + 1 }
Decrement ->
{ model | count = model.count - 1 }
view : Model -> Html (Msg Model)
view model =
div []
[ button [ onClick<| Increment model] [ text "+1" ]
, div [] [ text <| String.fromInt model.count ]
, button [ onClick Decrement ] [ text "-1" ]
]
main : Program () Model (Msg Model)
main =
Browser.sandbox
{ init = initialModel
, view = view
, update = update
}
I get the following error:
Something is off with the body of the `view` definition:
34|> div []
35|> [ button [ onClick<| Increment model] [ text "+1" ]
36|> , div [] [ text <| String.fromInt model.count ]
37|> , button [ onClick Decrement ] [ text "-1" ]
38|> ]
This `div` call produces:
Html (Msg {})
But the type annotation on `view` says it should be:
Html (Msg Model)
Hint: Looks like the count field is missing.
Can anyone help me figure this out? Thanks!