intro to elm

24
Elm The best of functional programming in your browser

Upload: thoughtbot

Post on 15-Feb-2017

185 views

Category:

Software


0 download

TRANSCRIPT

Elm

The best of functional programming in your browser

What is Elm? ● Purely functional● Statically typed● In the browser

Pure Functions

Static Typing

Better Modeling with Custom STatic types

type Approval = Approved | Rejected | Pending

In the Browser

User Friendly

Writing great code should be easy… now it is

Handling Nothing Life without null

Maybetype Maybe a = Nothing | Just a

> Nothing

Nothing : Maybe a

> Just "hello"

Just "hello" : Maybe String

Side effects The real world

Effects as Data

Random

HTTP

Time

websockets

The Elm Architecture Simple patterns that scale

Modeltype alias Model = Int

model = 0

Viewview : Model -> Html Msg

view model =

div []

[ button [ onClick Decrement ] [ text "-" ]

, div [] [ text (toString model) ]

, button [ onClick Increment ] [ text "+" ]

]

Updatetype Msg = Increment | Decrement

update : Msg -> Model -> Model

update msg model =

case msg of

Increment -> model + 1

Decrement -> model - 1

Components

Elm 0.17 Even more awesome

Simplified concepts● Commands● Subscriptions

Better Docs

Questions?