Skip to content

Instantly share code, notes, and snippets.

@jbmilgrom
Created February 29, 2020 17:24
Show Gist options
  • Save jbmilgrom/baddfa2e56f17a3e047905caca86b2ee to your computer and use it in GitHub Desktop.
Save jbmilgrom/baddfa2e56f17a3e047905caca86b2ee to your computer and use it in GitHub Desktop.
Counter example from https://guide.elm-lang.org/
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
main =
Browser.sandbox { init = 0, update = update, view = view }
type Msg = Increment | Decrement
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (String.fromInt model) ]
, button [ onClick Increment ] [ text "+" ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment