Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to elm lang

sarcilav
October 16, 2015

Intro to elm lang

Talk given at http://fest.colombia-dev.org/

Functional programming for your web browser, with love from Medellín.

sarcilav

October 16, 2015
Tweet

More Decks by sarcilav

Other Decks in Programming

Transcript

  1. 3 => 3 3.1415 => 3.1415 "Hello world!" => "Hello

    world!" true => True [1,2,3] => [1,2,3]
  2. JS

  3. $ node js-ex/ex1.js /Users/sarcilav/Desktop/fest/js-ex/ex1.js:1 n (exports, require, module, __filename, __dirname)

    { var message = "Hello wor ^^^^^^^^^^^^^^ SyntaxError: Unexpected token ILLEGAL at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3
  4. elm

  5. elm-make e1.e ## ERRORS in e1.e ############################################################## -- SYNTAX PROBLEM

    --------------------------------------------------------- e1.e I ran into something unexpected when parsing your code! 1| let message = "Hello World! ^ I am looking for one of the following things: "\"" "\\" "\n" "\r" Detected errors in 1 module.
  6. numbers = [ 1, 2, 3 ] first = List.head

    numbers last = List.head (List.reverse numbers) firstAndLast = first + last
  7. JS

  8. NaN

  9. ???

  10. $ elm-make e2.elm ## ERRORS in e2.elm ############################################################ -- TYPE

    MISMATCH -------------------------------------------------------- e2.elm The right argument of (+) is causing a type mismatch. 7| first + last ^^^^ As I infer the type of values flowing through your program, I see a conflict between these two types: number Maybe number ...
  11. -- TYPE MISMATCH -------------------------------------------------------- e2.elm The left argument of (+)

    is causing a type mismatch. 7| first + last ^^^^^ As I infer the type of values flowing through your program, I see a conflict between these two types: number Maybe number Detected errors in 1 module.
  12. numbers = [ 1, 2, 3 ] first = Maybe.withDefault

    0 (List.head numbers) last = Maybe.withDefault 0 (List.head (List.reverse numbers)) firstAndLast = first + last
  13. import List exposing (..) import Maybe exposing (withDefault) numbers =

    [ 1, 2, 3 ] first = withDefault 0 (head numbers) last = withDefault 0 (head (reverse numbers)) firstAndLast = first + last
  14. $ elm-make e2.elm ## ERRORS in e2.elm ############################################################ -- NAMING

    ERROR --------------------------------------------------------- e2.elm Cannot find variable `List.heat`. 15| first = List.heat numbers ^^^^^^^^^ `List` does not expose `heat`. Maybe you want one of the following? List.head Detected errors in 1 module.
  15. $ elm-make e2.elm ## ERRORS in e2.elm ############################################################ -- NAMING

    ERROR --------------------------------------------------------- e2.elm Cannot find variable `heat` 15| first = heat numbers ^^^^ Maybe you want one of the following? head List.head Detected errors in 1 module.
  16. Winners Om, Mercury, and Elm. All three of these projects

    are based on the Virtual DOM approach and make heavy use of immutability to get these speed gains.
  17. References (1) → Elm lang docs and references http://elm- lang.org/

    → Elm: Concurrent FRP for Functional GUIs, Evan Czaplicki, 30 March 2012.
  18. References (2) → Asynchronous Functional Reactive Programming for GUIs, Evan

    Czaplicki, Harvard University, [email protected], Stephen Chong, Harvard University, [email protected] → Mario example https://github.com/evancz/elm- examples/blob/master/Mario.elm → Benchmark http://evancz.github.io/todomvc-perf- comparison/