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
  • I actually do mostly PHP
  • 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

Why Pure Functions?

  • Reusable
  • Composable
  • Testable
  • Cacheable
  • Parallelizable
  • ...

Functional Programming

VS

Functional Programming Languages

Setting up the environment

npm install -g elm

alias elm='docker run -it --rm -v "$(pwd):/code" -w "/code" -e "HOME=/tmp" -u $UID:$GID -p 8000:8000 codesimple/elm:0.17'

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!

Let's write some

FUNCTIONS!

Partial applications

Forward pipe operator

|>

Anonymous functions

Let ... In ...

Prefix functions
 VS
Infix functions

Function composition

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

Accesing properties

Updating properties

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

Union types

A value that could be of multiple types

Union types

Pattern matching

Maybe and Result

Type aliases

Just do it!

The Elm Architecture

Like Redux but without JS

(Also called Flux)

That's all folks!

Questions?

Some resources

Some examples

Some spam

An introduction to Elm

By david_hernandez

An introduction to Elm

  • 1,957