Skip to content

Instantly share code, notes, and snippets.

@iwillspeak
Created May 2, 2018 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwillspeak/57596ba85fe7ae5744c1b8d089765e11 to your computer and use it in GitHub Desktop.
Save iwillspeak/57596ba85fe7ae5744c1b8d089765e11 to your computer and use it in GitHub Desktop.
Simple Elm Counter
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main = Html.beginnerProgram { model = model, view = view, update = update }
--- MODEL
type alias Model = Int
model : Model
model =
0
-- UPDATE
type Msg = Increment | Decrement | Reset
update : Msg -> Model -> Model
update msg model =
case msg of
Increment -> model + 1
Decrement -> model - 1
Reset -> 0
-- VIEW
view : Model -> Html Msg
view model =
p []
[ button [ onClick Decrement ] [ text "<" ]
, span [] [ text (toString model) ]
, button [ onClick Increment ] [ text ">" ]
, button [ onClick Reset, disabled (model == 0) ] [ text "Reset" ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment