Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. module Main exposing (..)
  2.  
  3. import Html exposing (..)
  4. import Html.Attributes exposing (..)
  5. import Html.Events exposing (..)
  6. import Html.App as App
  7. import String
  8.  
  9.  
  10. -- model
  11.  
  12.  
  13. type alias Model =
  14. String
  15.  
  16.  
  17. initModel : Model
  18. initModel =
  19. ""
  20.  
  21.  
  22.  
  23. -- update
  24.  
  25.  
  26. type Msg
  27. = ChangeInput String
  28.  
  29.  
  30. nextInput : String -> String -> String
  31. nextInput current new =
  32. case String.toInt new of
  33. Ok _ ->
  34. new
  35.  
  36. Err _ ->
  37. if new == "" then
  38. new
  39. else
  40. current
  41.  
  42.  
  43. update : Msg -> Model -> Model
  44. update msg model =
  45. case msg of
  46. ChangeInput newInput ->
  47. nextInput model newInput
  48.  
  49.  
  50.  
  51. -- view
  52.  
  53.  
  54. view : Model -> Html Msg
  55. view model =
  56. div []
  57. [ input
  58. [ type' "text"
  59. , value model
  60. , onInput ChangeInput
  61. ]
  62. []
  63. ]
  64.  
  65.  
  66. main : Program Never
  67. main =
  68. App.beginnerProgram
  69. { model = initModel
  70. , update = update
  71. , view = view
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement