Advertisement
Guest User

Untitled

a guest
Nov 13th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Html exposing (..)
  2. import Html.Attributes exposing (..)
  3. import Html.Events exposing (..)
  4. import StartApp.Simple as StartApp
  5. import String
  6.  
  7.  
  8. main =
  9.   StartApp.start { model = initialModel, view = view, update = update }
  10.  
  11.  
  12. -- MODEL
  13.  
  14. initialModel =
  15.   { topField = ""
  16.   , bottomField = ""
  17.   }
  18.  
  19.  
  20. -- UPDATE
  21.  
  22. type Action = Top String | Bottom String
  23.  
  24.  
  25. update action model =
  26.   case action of
  27.     Top str ->
  28.       { model | topField <- str }
  29.  
  30.     Bottom str ->
  31.       { model | bottomField <- str }
  32.  
  33.  
  34. -- VIEW
  35.  
  36. view address model =
  37.   div []
  38.     [ input
  39.         [ value model.topField
  40.         , on "input" targetValue (Signal.message address << Top)
  41.         ]
  42.         []
  43.     , input
  44.         [ value model.bottomField
  45.         , on "input" targetValue (Signal.message address << Bottom)
  46.         ]
  47.         []
  48.     , input
  49.         [ value (toSum model)
  50.         , on "input" targetValue (Signal.message address << Bottom)
  51.         , readonly True
  52.         ]
  53.         []
  54.     ]
  55.  
  56.  
  57. toSum {topField, bottomField} =
  58.   case Result.map2 (+) (String.toInt topField) (String.toInt bottomField) of
  59.     Err _ ->
  60.       ""
  61.  
  62.     Ok n ->
  63.       toString n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement