Elm Express

Miguel Cobá / @MiguelCobaMtz

Why not JS?

Writing JS is hard!

Requires

  • Knowledge
  • Discipline

Elm

A delightful language for reliable webapps

  • Powerful
  • Simple

Elm benefits

  • JavaScript Interop
  • No runtime exceptions
  • Easy Refactorings
  • Improved productivity
  • Testable Code
  • Helpful type systems

Easy Refactorings

Change code with confidence

The compiler will catch any error

Improved productivity

Immutable data

Pure functions

Testable code

All the data they need is passed

They no have side effects

Helpful type system

Non intrusive

Inferred

Pure function

Has no side effects

Its return value is based on input parameters

Does not use global state

Benefits of pure functions

Reusable

Composable

Testable

Cacheable

Parallelizable

Other Type Systems

Type declarations are verbose

Cryptic Error Messages

Still have runtime errors

Elm Type System

Types are inferred

Errors are friendly and helpful

No runtime exceptions

Feels like using a dynamic language

The Elm Architecture

A simple pattern for architecting webapps

Great for modularity, code reuse, and testing

Model

The state of your application


type alias Model =
    Int

initialModel =
        0
						

Update

A way to update your state


type Msg = Increment | Decrement

update: Msg -> Model -> Model
update msg model =
    case msg of
        Increment ->
            model + 1
        
        Decrement ->
            model - 1
						

View

A way to view your state as HTML


view : Model -> Html Msg
view model =
    div []
        [ button [ onClick Decrement ] [ text "-" ]
        , div [] [ text (toString model) ]
        , button [ onClick Increment ] [ text "+" ]
        ]
						

Elm Application


main =
    Html.beginnerProgram
        { model = initialModel
        , view = view
        , update = update
        }
						

Examples

Install

http://elm-lang.org

Learn

http://courses.knowthen.com/p/elm-for-beginners

Elm Guide

Elm Tutorial

Richard Feldmand's Intro to Elm

Thank you!

Miguel Cobá

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.