An introduction to Elm

Some rules

  • This is not a class. Interrumpt me!
  • Do you have a question? Ask away!
  • I might be wrong. Correct me!

Disclaimer

  • I am no expert
  • I am backend developer
  • You will see some serius bad jokes

Before we get started

Let's get rid of something

An Elm developer

is an Elmo

Something about me

What is Elm?

Funct lang
Compiled
For the Web

Why Elm?

Not Javascript
Fast
Good practices

What is Functional Programing?

Almost exclusive use of Pure Functions

What is a Pure Function?

  • Has no side effects
  • No state values
  • Has attributes
  • Return depends only on input
// There is an state.
var counter = 1;

function addCounterAndIncreaseIt(num) {
    // Output does not depend only on input.
    num += counter;

    // Has a side effect.
    counter++;

    return num;
}

var a = addCounterAndIncreaseIt(1);

// a is 2.
// counter is 2.

var b = addCounterAndIncreaseIt(1);

// b is 3.
// counter is 3.
function add(a, b) {
    return a + b;
}

var a = add(1, 2);
var b = add(1, 2);

// a is 3.
// b is 3.

Setting up the environment

npm install -g elm

What comes with Elm?

REPL

An interactive shell that lets you interact with values and functions directly.

Reactor

Dinamically compiles Elm files on demand and starts a server to test them on the browser.

Make

The Elm compiler.

 

Generates the HTML or JavaScript output.

Package

Package manager.

 

  • Downloads dependencies.
  • Publishes packages.
  • Updates dependencies.
  • Shows differences between versions

A bit more about packages

  • Only handles contributed packages
  • Enforces semantic versioning
  • Find them at http://package.elm-lang.org/

That's pretty cool but...

SHOW
ME THE
CODE!

Elm Static Types

  • Types are inferred
  • Friendly errors
  • No runtime exceptions

Totally not

JAVA

Elm Variable Types

What types do you know?

  • String
  • Char
  • Bool
  • Float
  • Int
  • Lists
  • Tuples
  • Objects?

Elm Records

Elm Records

Kind of a JS object

Some rules

  • Fields most exists
  • Cannot be null
  • Group of related fields
  • No self references

Are we missing something?

Where is the

null?

null is null

I mean... There is no null

Null, I call it my billion-dollar mistake

Tony Hoare, inventor of null

Type aliases

The Elm Architecture

Like Redux but without JS

(Also called Flux)

Just do it!

That's all folks!

Questions?

Some resources

Some examples

Some spam

About the session

An introduction to Elm v2

By david_hernandez

An introduction to Elm v2

  • 1,925