Skip to content

Instantly share code, notes, and snippets.

@napcs
Created December 31, 2015 01:29
Show Gist options
  • Save napcs/56321e38e9e0c2354e96 to your computer and use it in GitHub Desktop.
Save napcs/56321e38e9e0c2354e96 to your computer and use it in GitHub Desktop.
EFP #1 in Elm
-- 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