Created
December 31, 2015 01:29
-
-
Save napcs/56321e38e9e0c2354e96 to your computer and use it in GitHub Desktop.
EFP #1 in Elm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Exercises For Programmers #1 | |
import Html exposing (Html, text, div, p, input, label) | |
import Html.Attributes exposing (id, value, for) | |
import Html.Events exposing(on, targetValue) | |
import StartApp.Simple as StartApp | |
import Signal exposing (Address) | |
type Action | |
= NoOp | |
| UpdateModel String | |
model : String | |
model = | |
"" | |
view : Address Action -> String -> Html | |
view address model = | |
div [] [ | |
label [for "name"] [text "Enter your name"], | |
input [ | |
id "name", | |
on "input" targetValue (\value -> Signal.message address (UpdateModel value)), | |
value model ] [], | |
p [] [ text (output model)] | |
] | |
output string = | |
if string == "" then "Enter your name in the box." else "Hello, " ++ string | |
update action model = | |
case action of | |
NoOp -> | |
model | |
UpdateModel name -> | |
name | |
main = | |
StartApp.start { model = "", view = view, update = update } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment