...and hopefully ignite your curiosity!
type alias X =
{ a : Int
, b : String }
foo : X
foo = { a = 3
, b = "wowzers" }
bar : X
bar = { foo | a = 5 }
bar == { a = 5
, b = "wowzers" }foo : Int -> Int -> Int
foo x y = x + x + y// scala
def foo(x:Int)(y:Int):Int = x + x + y
// es6
const foo = x => y => x + x + y
// c#
Func<int, Func<int, int>> foo = x => y => x + x + y;(\x -> x * x)// scala
(x:Int => x * x)
// es6
(x => x * x)
// es5
(function(x){ return x * x; })
// math
λx. x * x4 |> foo == foo 4
4 |> (\x -> x + 4) |> toString == "8"[1,2] ++ [3,4] == [1,2,3,4]
"hi" ++ " " ++ "there" == "hi there"foo : Int -> String -> String
foo 3 : String -> String
foo 3 "bar" : StringElm Runtime
Real World
type Msg
= SummerWheatley
| PedroSanchez
type alias Model =
{ summerWheatley : Int
, pedroSanchez : Int }
init : Model
init =
{ summerWheatley = 0
, pedroSanchez = 0 }
update : Msg -> Model -> Model
update msg model =
case msg of
SummerWheatley ->
{ model |
summerWheatley = model.summerWheatley + 1 }
PedroSanchez ->
{ model |
pedroSanchez = model.pedroSanchez + 1 }
view : Model -> Html Msg
view model = div []
[ text "Vote for:"
, button [ onClick SummerWheatley ] [ text "Wheatley" ]
, button [ onClick PedroSanchez ] [ text "Sanchez" ]
]Renderer
Fold
State
Elm Runtime
Real World
type Msg
= SummerWheatley
| PedroSanchez
type alias Model =
{ summerWheatley : Int
, pedroSanchez : Int }
init : Model
init =
{ summerWheatley = 0
, pedroSanchez = 0 }
update : Msg -> Model -> Model
update msg model =
case msg of
SummerWheatley ->
{ model |
summerWheatley = model.summerWheatley + 1 }
PedroSanchez ->
{ model |
pedroSanchez = model.pedroSanchez + 1 }
view : Model -> Html Msg
view model = div []
[ text "Vote for:"
, button [ onClick SummerWheatley ] [ text "Wheatley" ]
, button [ onClick PedroSanchez ] [ text "Sanchez" ]
]Renderer
Fold
State
Model
Elm Runtime
Real World
type Msg
= SummerWheatley
| PedroSanchez
type alias Model =
{ summerWheatley : Int
, pedroSanchez : Int }
init : Model
init =
{ summerWheatley = 0
, pedroSanchez = 0 }
update : Msg -> Model -> Model
update msg model =
case msg of
SummerWheatley ->
{ model |
summerWheatley = model.summerWheatley + 1 }
PedroSanchez ->
{ model |
pedroSanchez = model.pedroSanchez + 1 }
view : Model -> Html Msg
view model = div []
[ text "Vote for:"
, button [ onClick SummerWheatley ] [ text "Wheatley" ]
, button [ onClick PedroSanchez ] [ text "Sanchez" ]
]Renderer
Sanchez
Html Msg
Fold
State
Model
Wheatley
Our user carefully considers...
Elm Runtime
Real World
type Msg
= SummerWheatley
| PedroSanchez
type alias Model =
{ summerWheatley : Int
, pedroSanchez : Int }
init : Model
init =
{ summerWheatley = 0
, pedroSanchez = 0 }
update : Msg -> Model -> Model
update msg model =
case msg of
SummerWheatley ->
{ model |
summerWheatley = model.summerWheatley + 1 }
PedroSanchez ->
{ model |
pedroSanchez = model.pedroSanchez + 1 }
view : Model -> Html Msg
view model = div []
[ text "Vote for:"
, button [ onClick SummerWheatley ] [ text "Wheatley" ]
, button [ onClick PedroSanchez ] [ text "Sanchez" ]
]Renderer
Sanchez
Fold
Msg
State
Model
Wheatley
Elm Runtime
Real World
type Msg
= SummerWheatley
| PedroSanchez
type alias Model =
{ summerWheatley : Int
, pedroSanchez : Int }
init : Model
init =
{ summerWheatley = 0
, pedroSanchez = 0 }
update : Msg -> Model -> Model
update msg model =
case msg of
SummerWheatley ->
{ model |
summerWheatley = model.summerWheatley + 1 }
PedroSanchez ->
{ model |
pedroSanchez = model.pedroSanchez + 1 }
view : Model -> Html Msg
view model = div []
[ text "Vote for:"
, button [ onClick SummerWheatley ] [ text "Wheatley" ]
, button [ onClick PedroSanchez ] [ text "Sanchez" ]
]Renderer
Sanchez
Html Msg
Fold
State
Model
Wheatley
Elm Runtime
Real World
type Msg
= SummerWheatley
| PedroSanchez
type alias Model =
{ summerWheatley : Int
, pedroSanchez : Int }
init : Model
init =
{ summerWheatley = 0
, pedroSanchez = 0 }
update : Msg -> Model -> Model
update msg model =
case msg of
SummerWheatley ->
{ model |
summerWheatley = model.summerWheatley + 1 }
PedroSanchez ->
{ model |
pedroSanchez = model.pedroSanchez + 1 }
view : Model -> Html Msg
view model = div []
[ text "Vote for:"
, button [ onClick SummerWheatley ] [ text "Wheatley" ]
, button [ onClick PedroSanchez ] [ text "Sanchez" ]
]Renderer
Sanchez
Html Msg
Fold
Msg
State
Model
Wheatley
The Elm Architecture
is based on the fold-ability of
immutable streams called Signals.
Once the pattern was established, working with
Signals became mostly boilerplate.
Elm has since baked the
programming model into the runtime,
making Signals completely opaque!
(types and good design)
Thank you everyone.