The Elm Talk
Abhishek Yadav
ப்ரோக்ராமர்
Co-organizer: Chennai.js
@h6165
The agenda
Elm
- The goal and the claims
- Functional programming
- Type system
- The Ecosystem
- Challenges
The goal and the claims
Elm
- No run-time errors
- Reactive UI
Introduction
Elm
Elm is a typed, pure functional programming language that compiles to Javascript.
typed: values and functions have types. Various type concepts are supported - type checking, inferred types, generics, union types, algebraic data types. There are no typeclasses
functional: functional programming concepts are supported (anonymous functions, higher order functions, currying, immutability etc)
Compiles to Javascript: Implements a Virtual-dom, supports Redux-like pattern, and (kind of) components. Provides module system and build tooling.
Introduction
Elm
Practically speaking ...
Typed: catch errors by compiling
Functional: no internal state. no mutables.
Compiles to Javascript: Run in browser, React+Redux+Webpack
No run time errors
Elm
What errors ?
The most common ones -
- Undefined is not a function
- NaN
We forgot to check for undefined/null values
We did math on a non-number
No run time errors
Elm
Type checking can help with both
-- total is a function that takes two Int values,
-- and produces an Int value
total: Int -> Int -> Int
total x y =
x + y
-- This will fail compilation
total 2 "2"
No run time errors
Elm
And for empty values, it forces us to handle them
-- total is a function that takes two Int values,
-- and produces an Int value
showFirst: List a -> String
showFirst myList =
case (List.head myList) of
Just x ->
toString x
Nothing ->
""
-- 1. List.head gives a value of Maybe type
-- 2. Will fail compilation if we don't handle the Nothing case
The Elm Talk
By Abhishek Yadav
The Elm Talk
- 926