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

Functional Fun – an Introduction to Elm

designrubenz
September 28, 2016

Functional Fun – an Introduction to Elm

from my talk at the September Web Dev Meetup in Salzburg, Austria
Sept 28 2016

designrubenz

September 28, 2016
Tweet

Other Decks in Programming

Transcript

  1. Elm A delightful language for reliable webapps Generate JavaScript with

    great performance and no runtime exceptions http://elm-lang.org/ „ Evan Czaplicki
  2. 4 Main Programming Paradigms source: Kurt Nørmark Imperative / Procedural

    First do this and next do that Logic Answer a question via search for a solution Object-oriented Send messages between objects to simulate the temporal evolution of a set of real world phenomena Functional Evaluate an expression and use the resulting value for something
  3. Pure functions source: knowthen.com •  must have input parameters • 

    must not use state •  must return value •  must not cause side effects
  4. Elm Eco System •  REPL elm-repl •  Package management elm-package

    install package •  Development tool (server, compiler) elm-reactor
  5. The Elm Architecture Html.App.beginnerProgram ELM RUNTIME Model view HTML handling

    events (click, input, ...) Msg update Model Model Model Model
  6. Embedding Elm in HTML var Elm = {}; Elm.MyThing =

    { fullscreen: function() { /* take over the <body> */ }, embed: function(node) { /* take over the given node */ }, worker: function() { /* run the program with no UI */ } }; Elm sets up this API for you:
  7. Embedding Elm in HTML fullscreen •  elm-make Greeter.elm --output greeter.js

    <!DOCTYPE html> <html lang="de"> <body> <script src="greeter.js"></script> <script> var app = Elm.Greeter.fullscreen(); </script> </body> </html>
  8. Embedding Elm in HTML embed •  elm-make Greeter.elm --output greeter.js

    <div id="my-thing"></div> <script src="my-thing.js"></script> <script> var node = document.getElementById('my-thing'); var app = Elm.MyThing.embed(node); </script>
  9. Resources My Github Gist „Starting with Elm“ •  https://gist.github.com/designrubenz/ f166cb4aff450881f2e0de0effb533d4

    Workshops, Code, Consultancy •  j_rubenz •  http://design.rubenz.at Barcamp Workshop
  10. The Elm Architecture Html.App.program ELM RUNTIME Model view HTML SubscripEons

    (websockets, Eme, locaEon changes) Msg update Cmd Msg Sub Msg Ports Commands (HTTP requests, Randomness) Land of Impurity