“Hello world!” from elm

in code


I am teaching myself functional programming and MV JavaScript applications by way of Elm. Although Elm has so far managed to wreck my head, parts of it have begun to be less opaque.

/tooting intensifies

import Html exposing (Html, text, div, button, h3)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)

main =
  beginnerProgram { model = model, view = view, update = update }

-- Model

type alias Model = { content: String }

model : Model
model = { content = "Click a button to see a message!" }

-- Update

type Msg = Hello | Goodbye

update : Msg -> Model -> Model
update msg model =
  case msg of
    Hello -> { model | content = "Hello world!" }
    Goodbye -> { model | content = "Goodbye world!" }

-- View

view : Model -> Html Msg
view model =
  div [] 
    [ h3 [] [ text model.content ]
    , button [ onClick Hello ] [ text "Hello" ]
    , button [ onClick Goodbye ] [ text "Goodbye" ]
    ]


A Summer of Running

in running

Achill Half Marathon

in running


Your email address will not be published. Required fields are marked *