Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Html exposing (..)
- import Html.Attributes exposing (..)
- import Html.Events exposing (..)
- import StartApp.Simple as StartApp
- import String
- main =
- StartApp.start { model = initialModel, view = view, update = update }
- -- MODEL
- initialModel =
- { topField = ""
- , bottomField = ""
- }
- -- UPDATE
- type Action = Top String | Bottom String
- update action model =
- case action of
- Top str ->
- { model | topField <- str }
- Bottom str ->
- { model | bottomField <- str }
- -- VIEW
- view address model =
- div []
- [ input
- [ value model.topField
- , on "input" targetValue (Signal.message address << Top)
- ]
- []
- , input
- [ value model.bottomField
- , on "input" targetValue (Signal.message address << Bottom)
- ]
- []
- , input
- [ value (toSum model)
- , on "input" targetValue (Signal.message address << Bottom)
- , readonly True
- ]
- []
- ]
- toSum {topField, bottomField} =
- case Result.map2 (+) (String.toInt topField) (String.toInt bottomField) of
- Err _ ->
- ""
- Ok n ->
- toString n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement