Skip to content

Instantly share code, notes, and snippets.

@benjamintanweihao
Created May 2, 2016 23:49
Show Gist options
  • Select an option

  • Save benjamintanweihao/d7b24778e202f6beec7b86120fc6860e to your computer and use it in GitHub Desktop.

Select an option

Save benjamintanweihao/d7b24778e202f6beec7b86120fc6860e to your computer and use it in GitHub Desktop.
module Counter (..) where
import Html exposing (..)
import Html.Events exposing (..)
import StartApp.Simple exposing (start)
-- MODEL
type alias Model =
Int
init : Model
init =
0
-- UPDATE
type Action
= Increment
| Decrement
update : Action -> Model -> Model
update action model =
case action of
Increment ->
model + 1
Decrement ->
model - 1
view : Signal.Address Action -> Model -> Html
view address model =
div
[]
[ button [ onClick address Decrement ] [ text "-" ]
, text (toString model)
, button [ onClick address Increment ] [ text "+" ]
]
main =
start { model = init, update = update, view = view }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment