Skip to content

Instantly share code, notes, and snippets.

@tjweir
Created November 29, 2015 17:59
Show Gist options
  • Save tjweir/d9fdb3fc65e29e39328b to your computer and use it in GitHub Desktop.
Save tjweir/d9fdb3fc65e29e39328b to your computer and use it in GitHub Desktop.
elm start app
import Html exposing (div, button, text)
import Html.Events exposing (onClick)
import StartApp.Simple as StartApp
main : Signal Html.Html
main =
StartApp.start { model = model, view = view, update = update }
model : Int
model = 0
view : Signal.Address Action -> a -> Html.Html
view address model =
div [ ]
[ div [] [ text (toString model) ]
, button [ onClick address Decrement ] [ text "-" ]
, button [ onClick address Increment ] [ text "+" ]
, button [ onClick address Reset ] [ text " RESET " ]
, button [ onClick address Double ] [ text " dub " ]
, button [ onClick address Triple ] [ text " trip " ]
]
type Action = Increment
| Decrement
| Reset
| Double
| Triple
mult : number -> number -> number
mult x y =
x * y
triple : number -> number
triple x =
mult 3 x
double : number -> number
double x =
mult 2 x
update : Action -> number -> number
update action model =
case action of
Increment -> model + 1
Decrement -> model - 1
Reset -> 0
Double -> double model
Triple -> triple model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment