Skip to content

Instantly share code, notes, and snippets.

@spg
Created November 27, 2015 01:03
Show Gist options
  • Save spg/cdcfeda5f796a35040eb to your computer and use it in GitHub Desktop.
Save spg/cdcfeda5f796a35040eb to your computer and use it in GitHub Desktop.
Elm counter
import Html exposing (div, button, text, input)
import Html.Events exposing (onClick)
import StartApp.Simple as StartApp
main =
StartApp.start { model = model, view = view, update = update }
model = 0
view address model =
div []
[ button [ onClick address Decrement ] [ text "-" ]
, div [] [ text (toString model) ]
, button [ onClick address Increment ] [ text "+" ]
, button [ onClick address Reset ] [ text "reset" ]
, input [ type "file" ] [ text "Select file" ]
]
type Action = Increment | Decrement | Reset
update action model =
case action of
Increment -> model + 1
Decrement -> model - 1
Reset -> 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment