Abhishek Yadav
ப்ரோக்ராமர்
Co-organizer: Chennai.js
@h6165
Elm
Elm
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.
Elm
Practically speaking ...
Typed: catch errors by compiling
Functional: no internal state. no mutables.
Compiles to Javascript: Run in browser, React+Redux+Webpack
Elm
What errors ?
The most common ones -
We forgot to check for undefined/null values
We did math on a non-number
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"
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