Intro to Elm

What is it?

  • Alternative to JS
  • Pure, static, strict functional language
  • Hindley-Milner type inference (like Haskell, OCaml, Rust, F# etc)
  • Very unlike implicit subtyping of e.g. Typescript
  • Prescribed architecture and comprehensive standard lib 
  • Motivations? Errors , stability, predictability

How does it work?

State

View

Update

init

Events

i.e. very much like a certain flavour of React

Demo

1​
1​
1​
1​
1 + 1 = 2
1 + 1 = 2
1​
2
2
2 * 2 = 4
1 + 4 = 5

Cardinality

String test = null;

//vs 

test = Nothing

C#: null inhabits every nullable type including String

 

Elm: Nothing only inhabits the Maybe type, there are no null strings, only strings inside Maybes

int? test = null;

Console.Write(test.Value);

//Kaboom! InvalidOperationException

test :: Maybe Int
test = Nothing

Debug.log "test" test

//Outputs Nothing

Are maybes like Nullables?

No - there is no unsafe equivalent of .Value

What's less than ideal about Typescript?

  • Unsound
  • type inference less good than H-M
  • Doesn't control side effects
  • Doesn't facilitate equational reasoning
  • Doesn't provide referential transparency
  • Lacks decent support for ADTs

Intro to Elm

By Julian Jelfs

Intro to Elm

  • 97