SlideShare a Scribd company logo
1 of 64
Download to read offline
Rethinking Front
End Development
With Elm
Brian Hogan
About me
ā€¢ I build web things.
ā€¢ I teach people.
ā€¢ I make music.
ā€¢ I write books.
Elm is a functional programming language like Haskell, but more
friendly, and aimed at front-end web development.
We use Elm to make our user interface and give it behavior.
Example
import Graphics.Element exposing (show)
main =
show "Hello World"
Elm compiles to JavaScript
Yes. We just wrote a bunch of code that gets injected into an HTML
page.
Feel gross yet?
That's what React does too.
var HelloMessage = React.createClass({
render: function () {
return <h1>Hello {this.props.message}!</h1>;
}
});
React.render(<HelloMessage message="World" />, document.body);
Okay, Why Elm?
ā€¢ Same concepts as React
ā€¢ Pure functions
ā€¢ Immutable State
ā€¢ Static Typing
What you need
ā€¢ Node.js http://nodejs.org
ā€¢ The elm package for Node
$ npm install -g elm
ā€¢ Your favorite text editor
OR
http://elm-lang.org/try
Compiling Elm
ā€¢ Create a hello.elm file
ā€¢ Run
$ elm make hello.elm
Success! Compiled 1 modules.
Successfully generated index.html
ā€¢ Open resulting index.html in your browser.
HTML
Comparison
ā€¢ Elm: ~5400 lines
ā€¢ React: ~19300 lines
ā€¢ JQuery: ~9800 lines
Elm Reactor
Elm Reactor compiles Elm to HTML on
each request.
$ elm-reactor
elm reactor 0.16.0
Listening on http://0.0.0.0:8000/
How Elm Works
Every Elm app calls a main function when we run it.
main =
-- something goes here
Functions
We define functions with a name followed by an = sign.
hello =
"Hello there"
We indent the definitions of functions.
We invoke this function like this:
hello
Arguments
Functions can have arguments
square number =
number * number
Call it as
square 2
They have explicit returns.
Multiple Arguments
Multiple arguments use spaces:
add number1 number2 =
number1 + number2
Call it as
add 1 2
Woah.... no commas!
Type annotations
We can enforce data types for our functions so Elm can help us out.
functionName: TypeOfArg1-> TypeOfArg2 -> TypeOfArg3 -> ReturnType
Annotation Examples:
No parameters. Just return value
hello: String
hello =
"Hello there"
Two parameters and a return value
add: Float -> Float -> Float
add number1 number2 =
number1 + number2
Modules
Define modules to group your code.
module Hello where
main =
-- something goes here
Html functions
The elm-html module exposes many functions for building up virtual
DOM nodes.
The main function can render HTML if the HTML module is included.
import Html exposing(p, text)
main =
p [] [text "Hello World"]
p and text
p [] [text "Hello World"]
p and text are two functions from elm-html
p takes two lists
ā€¢ a list of attributes (can be empty)
ā€¢ a list of child elements
text takes a string of text to display.
HTML functions are uniform.
Each takes attributes and elements. So we can nest them like HTML.
div [class "foo", id "bar" ] [
h1 [] [text "Hello"],
p [] [text "World"]
]
There's a function for every element. Just be sure to expose what you
use.
Seriously uniform
label [for "name"] [text "Name"]
input [id "name", type' "number", step "any"] []
Even functions for tags that don't allow inner content still take two
lists as arguments.
Html Modules
ā€¢ Html contains all the tags
ā€¢ Html.Attributes contains the attributes (like class, id, href,
etc)
ā€¢ Html.Events contains events like onClick
Html Attributes
import Html exposing(Html, div, text, p)
import Html.Attributes exposing(class)
main =
div [class "wrapper"] [
p [class "notice"] [text "This is important!"]
]
Composability
main =
view
view: Html
view =
div [] [
p [] [
text "Hello ",
em [] [text "world"]
]
]
Resuability
main =
div [] [
view "Hello",
view "Goodbye"
]
view: String -> Html
view word =
div [] [
p [] [ text (word ++ " "), em [] [text "world"] ]
]
Web Interfaces
import Html exposing(Html, Attribute, p, text)
import Html.Attributes exposing(style)
elementStyle: Attribute
elementStyle =
style [ ("color", "red") , ("font-size", "2em") ]
main: Html
main =
view
view =
p [elementStyle] [text "Hello World"]
Helpers!
ļ¬eldWithLabel: String -> String -> String -> Html
ļ¬eldWithLabel ļ¬eldID ļ¬eldName ļ¬eldType =
div [] [
label [for ļ¬eldID] [text ļ¬eldName],
input [ id ļ¬eldID, type' ļ¬eldType] []
]
Build Out The Helpers
numberField: String -> String -> Html
numberField ļ¬eldID ļ¬eldName =
ļ¬eldWithLabel ļ¬eldID ļ¬eldName "number"
textField: String -> String -> Html
textField ļ¬eldID ļ¬eldName =
ļ¬eldWithLabel ļ¬eldID ļ¬eldName "text"
emailField: String -> String -> Html
emailField ļ¬eldID ļ¬eldName =
ļ¬eldWithLabel ļ¬eldID ļ¬eldName "email"
Shiny Happy Frontend Code
main: Html
main =
div [] [
textField "name" "Name",
numberField "age" "Age",
emailField "email" "Email"
]
Elm Architecture
View: Function that fires when model changes. Transofms a model
into the UI that people see.
Model: Something that holds the current state of the app. No behavior.
Just the state. No behavior. This is not MVC with objects!
Update: Function that fires when state changes. Always returns a new
model.
Signals and Mailboxes
Signals
Signals route messages around the application. Pressing a button is a
signal. We can send data along signals.
Mailboxes
Mailboxes receive signals and send signals. A mailbox has an address
and a signal to respond to.
Basic Flow
ā€¢ Model is initialized
ā€¢ View is displayed with model
ā€¢ Events send Signals to Mailboxes
ā€¢ Mailboxes trigger updates
ā€¢ New model is created
ā€¢ New view is rendered
Yikes!
Elm StartApp.Simple
Like Flux, without all the code.
ā€¢ Define Actions
ā€¢ Define a model to represent data
ā€¢ Define a view function
ā€¢ Define an update function that returns a new model.
Change Text On Click
import Html exposing (Html, text, h1, p, div, button)
import StartApp.Simple as StartApp
import Html.Events exposing (onClick)
main =
StartApp.start {model = "Hello ", view = view, update = update}
view address initialText =
div [] [
h1 [] [text "Events"],
p [] [ text initialText ],
button [onClick address "change"] [text "Push me"]
]
update action model =
"it changed"
Actions
Actions get sent to the Update.
type Action = Increment | Decrement
model = 0
update: Signal.Action -> Int -> Int
update action model =
case action of
Increment -> model + 1
Decrement -> model - 1
Multiple events
main =
StartApp.start { model = model, view = view, update = update }
view: Signal.Address Action -> Int -> Html
view address model =
div []
[ button [ onClick address Increment ] [ text "Up" ]
, span [] [ text (toString model) ]
, button [ onClick address Decrement ] [ text "Down" ]
]
Once again...
ā€¢ StartApp renders the view using an initial model state.
ā€¢ Events defined in the view send Actions to Signal Addresses
which route to update.
ā€¢ update returns a new version of the model
ā€¢ StartApp causes the view to be rendered whenever model
changes.
Calculator
Compound Interest Calculator
Write a program to compute the value of an investment compounded
over time. The program should ask for the starting amount, the
number of years to invest, the interest rate, and the number of periods
per year to compound.
Project setup
Create folder and file to work in
$ mkdir calculator && cd calculator
$ touch calculator.elm
Init the project
$ elm package install
Install HTML and StartApp dependencies.
$ elm package install evancz/elm-html
$ elm package install evancz/start-app
Livereloading
Make browser reload when we save
$ npm install -g elm-live
$ elm-live calculator.elm
Steps
ā€¢ Create the basic app
ā€¢ Build the form
ā€¢ Bind form to model and define events
ā€¢ Perform calculations
ā€¢ Display Output
The Basic App
import Html exposing (Html, text, h1, p, div, button, label, input)
import Html.Attributes exposing ( style, for, id, step, type', value)
import StartApp.Simple as StartApp
import Html.Events exposing (onClick)
main =
StartApp.start {model = model, view = view, update = update}
Define a model and update
model: Float
model = 0
update: String -> Float -> Float
update action model =
model
Building the form
ā€¢ Use label, input functions
ā€¢ Use number fields
ā€¢ Each field change updates model state
ā€¢ Clicking button calculates new amount
numberField helper
numberField: String -> String -> Html
numberField ļ¬eldID ļ¬eldName =
div [] [
label [for ļ¬eldID] [text ļ¬eldName],
input [ id ļ¬eldID, type' "number", step "any"] []
]
Style the form
labelStyle: Attribute
labelStyle =
style
[ ("width", "200px")
, ("padding", "10px")
, ("text-align", "right")
, ("display", "inline-block")
]
Apply style to field
div [] [
label [labelStyle, for ļ¬eldID] [text ļ¬eldName],
input [ id ļ¬eldID, type' "number", step "any"] []
]
Build the View
view: Signal.Address String -> Float -> Html
view address model =
div [] [
h1 [] [text "Calculator"],
div [] [
numberField "principal" "Principal",
numberField "rate" "Rate",
numberField "years" "Periods",
numberField "years" "Years"
]
button [onClick address "calculate"] [text "Calculate"]
]
Define Our Actions
type Action
= NoOp
| SetPrinciple String
| SetPeriods String
| SetRate String
| SetYears String
| Calculate
Define A Model
type alias Model =
{ principle: String
, rate: String
, years: String
, periods: String
, newAmount: Float}
model: Model
model =
{ principle = "1500.00"
, rate = "4.3"
, years = "6"
, periods = "4"
, newAmount = 0 }
Pass address, action, and model data to fields
view: Signal.Address Action -> Model -> Html
view address model =
div [] [
h1 [] [text "Calculator"],
div [] [
numberField address SetPrinciple "principle" "Principle" model.principle,
numberField address SetRate "rate" "Rate" model.rate,
numberField address SetPeriods "periods" "Periods" model.periods,
numberField address SetYears "years" "Years" model.years
],
button [onClick address Calculate] [text "Click me"],
Add Events To Form using Actions and model data
numberField: Signal.Address Action -> (String -> Action) ->
String -> String -> String -> Html
numberField address action ļ¬eldID name ļ¬eldValue =
div [] [
label [labelStyle, for ļ¬eldID] [text name],
input [id ļ¬eldID, type' "number", step "any",
on "input" targetValue (Signal.message address << action ),
value ļ¬eldValue] []
]
Update model from form
update: Action -> Model -> Model
update action model =
case action of
NoOp -> model
SetPrinciple p -> {model | principle = p}
SetRate r -> {model | rate = r}
SetYears y -> {model | years = y}
SetPeriods p -> {model | periods = p}
Calculate -> calculateNewAmount model
The program Logic
compoundInterest: Float -> Float -> Float -> Float -> Float
compoundInterest principle rate periods years =
(principle * (1 + (rate / periods ) ) ^ (years * periods) )
Converting Strings To Floats
convertToFloat: String -> Float
convertToFloat string =
case String.toFloat string of
Ok n -> n
Err _ -> 0.0
Implement CalculateNewAmount
calculateNewAmount: Model -> Model
calculateNewAmount model =
let
rate = convertToFloat model.rate / 100
years = convertToFloat model.years
principle = convertToFloat model.principle
periods = convertToFloat model.periods
in
{model | newAmount = (compoundInterest principle rate periods years) }
Display the Output
output: Model -> Html
output model =
div [] [
span [] [text "Amount: "],
span [] [text (toString model.newAmount) ]
]
And add it to the view.
Discuss
What are your thoughts?
Is this cool? Good? Bad? A terrible idea or
the greatest thing ever?
Issues
1. Tons of code to do simple things
2. Integration with external services is
complex
3. Must re-learn a lot of things about web
development
4. Small community
Benefits
1. Small community
2. Benefits of React with a clear
opinionated approach
3. Fantastic error messages
4. Types ensure data integrity and flow
Write code
ā€¢ Elm website: http://elm-lang.org/
ā€¢ Try Elm http://elm-lang.org/try
ā€¢ Package system: http://package.elm-
lang.org/
ā€¢ Documentation http://elm-lang.org/docs
Where to go next?
Book: http://pragprog.com/titles/bhwb
Twitter: @bphogan
Material: http://bphogan.com/
presentations/elm2016/
Thank you!
Ā© Brian Hogan, 2016.
Photos from http://pexels.com

More Related Content

What's hot

A quick guide to Css and java script
A quick guide to Css and  java scriptA quick guide to Css and  java script
A quick guide to Css and java scriptAVINASH KUMAR
Ā 
WPF L02-Graphics, Binding and Animation
WPF L02-Graphics, Binding and AnimationWPF L02-Graphics, Binding and Animation
WPF L02-Graphics, Binding and AnimationMohammad Shaker
Ā 
HTML 5 Simple Tutorial Part 4
HTML 5 Simple Tutorial Part 4HTML 5 Simple Tutorial Part 4
HTML 5 Simple Tutorial Part 4Sanjeev Kumar
Ā 
1. introduction to html5
1. introduction to html51. introduction to html5
1. introduction to html5JayjZens
Ā 
Javascript
JavascriptJavascript
JavascriptNagarajan
Ā 
WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesWPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesMohammad Shaker
Ā 
Java Script ppt
Java Script pptJava Script ppt
Java Script pptPriya Goyal
Ā 
Students Stars
Students StarsStudents Stars
Students StarsOthaimeen
Ā 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Aaron Gustafson
Ā 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript WorkshopPamela Fox
Ā 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy stepsprince Loffar
Ā 
Html basics 10 form
Html basics 10 formHtml basics 10 form
Html basics 10 formH K
Ā 

What's hot (17)

Javascript
JavascriptJavascript
Javascript
Ā 
A quick guide to Css and java script
A quick guide to Css and  java scriptA quick guide to Css and  java script
A quick guide to Css and java script
Ā 
WPF L02-Graphics, Binding and Animation
WPF L02-Graphics, Binding and AnimationWPF L02-Graphics, Binding and Animation
WPF L02-Graphics, Binding and Animation
Ā 
HTML 5 Simple Tutorial Part 4
HTML 5 Simple Tutorial Part 4HTML 5 Simple Tutorial Part 4
HTML 5 Simple Tutorial Part 4
Ā 
1. introduction to html5
1. introduction to html51. introduction to html5
1. introduction to html5
Ā 
Java script
Java scriptJava script
Java script
Ā 
Javascript
JavascriptJavascript
Javascript
Ā 
WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesWPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
Ā 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Ā 
Java script
Java scriptJava script
Java script
Ā 
Students Stars
Students StarsStudents Stars
Students Stars
Ā 
Web programming
Web programmingWeb programming
Web programming
Ā 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
Ā 
Java script
Java scriptJava script
Java script
Ā 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript Workshop
Ā 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
Ā 
Html basics 10 form
Html basics 10 formHtml basics 10 form
Html basics 10 form
Ā 

Viewers also liked

Introduction to Elm
Introduction to ElmIntroduction to Elm
Introduction to ElmRogerio Chaves
Ā 
My adventure with Elm
My adventure with ElmMy adventure with Elm
My adventure with ElmYan Cui
Ā 
Elm a possible future for web frontend
Elm   a possible future for web frontendElm   a possible future for web frontend
Elm a possible future for web frontendGaetano Contaldi
Ā 
Claudia Doppioslash - Time Travel for game development with Elm
Claudia Doppioslash - Time Travel for game development with ElmClaudia Doppioslash - Time Travel for game development with Elm
Claudia Doppioslash - Time Travel for game development with ElmCodemotion
Ā 
Elm: frontend code without runtime exceptions
Elm: frontend code without runtime exceptionsElm: frontend code without runtime exceptions
Elm: frontend code without runtime exceptionsPietro Grandi
Ā 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patternsTomasz Kowal
Ā 
Elixir and elm - the perfect couple
Elixir and elm - the perfect coupleElixir and elm - the perfect couple
Elixir and elm - the perfect coupleTomasz Kowal
Ā 
Unic - frontend development-in-complex-projects
Unic - frontend development-in-complex-projectsUnic - frontend development-in-complex-projects
Unic - frontend development-in-complex-projectsUnic
Ā 
Technology independent UI development with JVx
Technology independent UI development with JVxTechnology independent UI development with JVx
Technology independent UI development with JVxSIB Visions GmbH
Ā 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web developmentAmir Barylko
Ā 
Web Frontend development: tools and good practices to (re)organize the chaos
Web Frontend development: tools and good practices to (re)organize the chaosWeb Frontend development: tools and good practices to (re)organize the chaos
Web Frontend development: tools and good practices to (re)organize the chaosMatteo Papadopoulos
Ā 
Agile IT: Modern Architecture for Rapid Mobile App Development
Agile IT: Modern Architecture for Rapid Mobile App DevelopmentAgile IT: Modern Architecture for Rapid Mobile App Development
Agile IT: Modern Architecture for Rapid Mobile App DevelopmentAnyPresence
Ā 
Basics of Rich Internet Applications
Basics of Rich Internet ApplicationsBasics of Rich Internet Applications
Basics of Rich Internet ApplicationsSubramanyan Murali
Ā 
Collaborative music with elm and phoenix
Collaborative music with elm and phoenixCollaborative music with elm and phoenix
Collaborative music with elm and phoenixJosh Adams
Ā 
Comparison of Java Web Application Frameworks
Comparison of Java Web Application FrameworksComparison of Java Web Application Frameworks
Comparison of Java Web Application FrameworksAngelin R
Ā 
Modern Rapid Application Development - Too good to be true
Modern Rapid Application Development - Too good to be trueModern Rapid Application Development - Too good to be true
Modern Rapid Application Development - Too good to be trueWaveMaker, Inc.
Ā 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsKonrad Malawski
Ā 

Viewers also liked (20)

Introduction to Elm
Introduction to ElmIntroduction to Elm
Introduction to Elm
Ā 
My adventure with Elm
My adventure with ElmMy adventure with Elm
My adventure with Elm
Ā 
Elm a possible future for web frontend
Elm   a possible future for web frontendElm   a possible future for web frontend
Elm a possible future for web frontend
Ā 
Claudia Doppioslash - Time Travel for game development with Elm
Claudia Doppioslash - Time Travel for game development with ElmClaudia Doppioslash - Time Travel for game development with Elm
Claudia Doppioslash - Time Travel for game development with Elm
Ā 
Elm: frontend code without runtime exceptions
Elm: frontend code without runtime exceptionsElm: frontend code without runtime exceptions
Elm: frontend code without runtime exceptions
Ā 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
Ā 
Elixir and elm - the perfect couple
Elixir and elm - the perfect coupleElixir and elm - the perfect couple
Elixir and elm - the perfect couple
Ā 
Unic - frontend development-in-complex-projects
Unic - frontend development-in-complex-projectsUnic - frontend development-in-complex-projects
Unic - frontend development-in-complex-projects
Ā 
Technology independent UI development with JVx
Technology independent UI development with JVxTechnology independent UI development with JVx
Technology independent UI development with JVx
Ā 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
Ā 
Web Frontend development: tools and good practices to (re)organize the chaos
Web Frontend development: tools and good practices to (re)organize the chaosWeb Frontend development: tools and good practices to (re)organize the chaos
Web Frontend development: tools and good practices to (re)organize the chaos
Ā 
Agile IT: Modern Architecture for Rapid Mobile App Development
Agile IT: Modern Architecture for Rapid Mobile App DevelopmentAgile IT: Modern Architecture for Rapid Mobile App Development
Agile IT: Modern Architecture for Rapid Mobile App Development
Ā 
Basics of Rich Internet Applications
Basics of Rich Internet ApplicationsBasics of Rich Internet Applications
Basics of Rich Internet Applications
Ā 
Collaborative music with elm and phoenix
Collaborative music with elm and phoenixCollaborative music with elm and phoenix
Collaborative music with elm and phoenix
Ā 
Functional Web Development using Elm
Functional Web Development using ElmFunctional Web Development using Elm
Functional Web Development using Elm
Ā 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
Ā 
Comparison of Java Web Application Frameworks
Comparison of Java Web Application FrameworksComparison of Java Web Application Frameworks
Comparison of Java Web Application Frameworks
Ā 
React redux
React reduxReact redux
React redux
Ā 
Modern Rapid Application Development - Too good to be true
Modern Rapid Application Development - Too good to be trueModern Rapid Application Development - Too good to be true
Modern Rapid Application Development - Too good to be true
Ā 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applications
Ā 

Similar to Rethink Frontend Development With Elm

Elm 0.17 at Dublin Elm Meetup May 2016
Elm 0.17 at Dublin Elm Meetup May 2016Elm 0.17 at Dublin Elm Meetup May 2016
Elm 0.17 at Dublin Elm Meetup May 2016Michael Twomey
Ā 
Html css
Html cssHtml css
Html cssJohn Felix
Ā 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
Ā 
Scripting languages
Scripting languagesScripting languages
Scripting languagesteach4uin
Ā 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm UpMohammad Shaker
Ā 
dotnetConf2019 meetup in AICHI / Elmish
dotnetConf2019 meetup in AICHI / ElmishdotnetConf2019 meetup in AICHI / Elmish
dotnetConf2019 meetup in AICHI / ElmishMidoliy
Ā 
Html5ppt
Html5pptHtml5ppt
Html5pptrecroup
Ā 
A proper introduction to Elm
A proper introduction to ElmA proper introduction to Elm
A proper introduction to ElmJohannes Ridderstedt
Ā 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4DEVCON
Ā 
HTML5 - Quick Guide
HTML5 - Quick GuideHTML5 - Quick Guide
HTML5 - Quick GuideBhaumik Patel
Ā 
What About Elm?
What About Elm?What About Elm?
What About Elm?Scott Smith
Ā 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorialAndi Simanjuntak
Ā 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Thinkful
Ā 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyUna Daly
Ā 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQueryorestJump
Ā 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Thinkful
Ā 
Web development (html)
Web development (html)Web development (html)
Web development (html)AliNaqvi131
Ā 

Similar to Rethink Frontend Development With Elm (20)

Elm 0.17 at Dublin Elm Meetup May 2016
Elm 0.17 at Dublin Elm Meetup May 2016Elm 0.17 at Dublin Elm Meetup May 2016
Elm 0.17 at Dublin Elm Meetup May 2016
Ā 
Html css
Html cssHtml css
Html css
Ā 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
Ā 
Scripting languages
Scripting languagesScripting languages
Scripting languages
Ā 
Javascript
JavascriptJavascript
Javascript
Ā 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
Ā 
dotnetConf2019 meetup in AICHI / Elmish
dotnetConf2019 meetup in AICHI / ElmishdotnetConf2019 meetup in AICHI / Elmish
dotnetConf2019 meetup in AICHI / Elmish
Ā 
Html5ppt
Html5pptHtml5ppt
Html5ppt
Ā 
A proper introduction to Elm
A proper introduction to ElmA proper introduction to Elm
A proper introduction to Elm
Ā 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
Ā 
HTML5 - Quick Guide
HTML5 - Quick GuideHTML5 - Quick Guide
HTML5 - Quick Guide
Ā 
Elm @ DublinJS
Elm @ DublinJSElm @ DublinJS
Elm @ DublinJS
Ā 
What About Elm?
What About Elm?What About Elm?
What About Elm?
Ā 
WEB DEVELOPMENT
WEB DEVELOPMENTWEB DEVELOPMENT
WEB DEVELOPMENT
Ā 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
Ā 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
Ā 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una Daly
Ā 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
Ā 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
Ā 
Web development (html)
Web development (html)Web development (html)
Web development (html)
Ā 

More from Brian Hogan

Creating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoCreating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoBrian Hogan
Ā 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleBrian Hogan
Ā 
Create Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantCreate Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantBrian Hogan
Ā 
Getting Started Contributing To Open Source
Getting Started Contributing To Open SourceGetting Started Contributing To Open Source
Getting Started Contributing To Open SourceBrian Hogan
Ā 
Testing Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptTesting Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptBrian Hogan
Ā 
FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.Brian Hogan
Ā 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignBrian Hogan
Ā 
Web Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassWeb Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassBrian Hogan
Ā 
Building A Gem From Scratch
Building A Gem From ScratchBuilding A Gem From Scratch
Building A Gem From ScratchBrian Hogan
Ā 
Intro To Advanced Ruby
Intro To Advanced RubyIntro To Advanced Ruby
Intro To Advanced RubyBrian Hogan
Ā 
Turning Passion Into Words
Turning Passion Into WordsTurning Passion Into Words
Turning Passion Into WordsBrian Hogan
Ā 
HTML5 and CSS3 Today
HTML5 and CSS3 TodayHTML5 and CSS3 Today
HTML5 and CSS3 TodayBrian Hogan
Ā 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexWeb Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexBrian Hogan
Ā 
Stop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryStop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryBrian Hogan
Ā 
Intro to Ruby
Intro to RubyIntro to Ruby
Intro to RubyBrian Hogan
Ā 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Brian Hogan
Ā 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with ShoesBrian Hogan
Ā 
The Why Of Ruby
The Why Of RubyThe Why Of Ruby
The Why Of RubyBrian Hogan
Ā 
Story-driven Testing
Story-driven TestingStory-driven Testing
Story-driven TestingBrian Hogan
Ā 

More from Brian Hogan (20)

Creating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoCreating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with Hugo
Ā 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and Ansible
Ā 
Create Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantCreate Development and Production Environments with Vagrant
Create Development and Production Environments with Vagrant
Ā 
Docker
DockerDocker
Docker
Ā 
Getting Started Contributing To Open Source
Getting Started Contributing To Open SourceGetting Started Contributing To Open Source
Getting Started Contributing To Open Source
Ā 
Testing Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptTesting Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScript
Ā 
FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.
Ā 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Ā 
Web Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassWeb Development with CoffeeScript and Sass
Web Development with CoffeeScript and Sass
Ā 
Building A Gem From Scratch
Building A Gem From ScratchBuilding A Gem From Scratch
Building A Gem From Scratch
Ā 
Intro To Advanced Ruby
Intro To Advanced RubyIntro To Advanced Ruby
Intro To Advanced Ruby
Ā 
Turning Passion Into Words
Turning Passion Into WordsTurning Passion Into Words
Turning Passion Into Words
Ā 
HTML5 and CSS3 Today
HTML5 and CSS3 TodayHTML5 and CSS3 Today
HTML5 and CSS3 Today
Ā 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexWeb Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To Complex
Ā 
Stop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryStop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard Library
Ā 
Intro to Ruby
Intro to RubyIntro to Ruby
Intro to Ruby
Ā 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7
Ā 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with Shoes
Ā 
The Why Of Ruby
The Why Of RubyThe Why Of Ruby
The Why Of Ruby
Ā 
Story-driven Testing
Story-driven TestingStory-driven Testing
Story-driven Testing
Ā 

Recently uploaded

Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
Ā 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
Ā 
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online ā˜‚ļø
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online  ā˜‚ļøCALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online  ā˜‚ļø
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online ā˜‚ļøanilsa9823
Ā 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
Ā 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
Ā 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
Ā 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
Ā 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
Ā 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
Ā 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
Ā 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
Ā 
(Genuine) Escort Service Lucknow | Starting ā‚¹,5K To @25k with A/C šŸ§‘šŸ½ā€ā¤ļøā€šŸ§‘šŸ» 89...
(Genuine) Escort Service Lucknow | Starting ā‚¹,5K To @25k with A/C šŸ§‘šŸ½ā€ā¤ļøā€šŸ§‘šŸ» 89...(Genuine) Escort Service Lucknow | Starting ā‚¹,5K To @25k with A/C šŸ§‘šŸ½ā€ā¤ļøā€šŸ§‘šŸ» 89...
(Genuine) Escort Service Lucknow | Starting ā‚¹,5K To @25k with A/C šŸ§‘šŸ½ā€ā¤ļøā€šŸ§‘šŸ» 89...gurkirankumar98700
Ā 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
Ā 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
Ā 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
Ā 
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
Ā 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
Ā 
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Steffen Staab
Ā 

Recently uploaded (20)

Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
Ā 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
Ā 
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online ā˜‚ļø
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online  ā˜‚ļøCALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online  ā˜‚ļø
CALL ON āž„8923113531 šŸ”Call Girls Kakori Lucknow best sexual service Online ā˜‚ļø
Ā 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
Ā 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
Ā 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Ā 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
Ā 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Ā 
Vip Call Girls Noida āž”ļø Delhi āž”ļø 9999965857 No Advance 24HRS Live
Vip Call Girls Noida āž”ļø Delhi āž”ļø 9999965857 No Advance 24HRS LiveVip Call Girls Noida āž”ļø Delhi āž”ļø 9999965857 No Advance 24HRS Live
Vip Call Girls Noida āž”ļø Delhi āž”ļø 9999965857 No Advance 24HRS Live
Ā 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
Ā 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
Ā 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
Ā 
(Genuine) Escort Service Lucknow | Starting ā‚¹,5K To @25k with A/C šŸ§‘šŸ½ā€ā¤ļøā€šŸ§‘šŸ» 89...
(Genuine) Escort Service Lucknow | Starting ā‚¹,5K To @25k with A/C šŸ§‘šŸ½ā€ā¤ļøā€šŸ§‘šŸ» 89...(Genuine) Escort Service Lucknow | Starting ā‚¹,5K To @25k with A/C šŸ§‘šŸ½ā€ā¤ļøā€šŸ§‘šŸ» 89...
(Genuine) Escort Service Lucknow | Starting ā‚¹,5K To @25k with A/C šŸ§‘šŸ½ā€ā¤ļøā€šŸ§‘šŸ» 89...
Ā 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
Ā 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
Ā 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Ā 
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )šŸ” 9953056974šŸ”(=)/CALL GIRLS SERVICE
Ā 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
Ā 
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Ā 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
Ā 

Rethink Frontend Development With Elm

  • 2. About me ā€¢ I build web things. ā€¢ I teach people. ā€¢ I make music. ā€¢ I write books.
  • 3. Elm is a functional programming language like Haskell, but more friendly, and aimed at front-end web development. We use Elm to make our user interface and give it behavior.
  • 4. Example import Graphics.Element exposing (show) main = show "Hello World"
  • 5. Elm compiles to JavaScript Yes. We just wrote a bunch of code that gets injected into an HTML page. Feel gross yet?
  • 6. That's what React does too. var HelloMessage = React.createClass({ render: function () { return <h1>Hello {this.props.message}!</h1>; } }); React.render(<HelloMessage message="World" />, document.body);
  • 7. Okay, Why Elm? ā€¢ Same concepts as React ā€¢ Pure functions ā€¢ Immutable State ā€¢ Static Typing
  • 8. What you need ā€¢ Node.js http://nodejs.org ā€¢ The elm package for Node $ npm install -g elm ā€¢ Your favorite text editor OR http://elm-lang.org/try
  • 9. Compiling Elm ā€¢ Create a hello.elm file ā€¢ Run $ elm make hello.elm Success! Compiled 1 modules. Successfully generated index.html ā€¢ Open resulting index.html in your browser.
  • 10. HTML
  • 11. Comparison ā€¢ Elm: ~5400 lines ā€¢ React: ~19300 lines ā€¢ JQuery: ~9800 lines
  • 12. Elm Reactor Elm Reactor compiles Elm to HTML on each request. $ elm-reactor elm reactor 0.16.0 Listening on http://0.0.0.0:8000/
  • 13. How Elm Works Every Elm app calls a main function when we run it. main = -- something goes here
  • 14. Functions We define functions with a name followed by an = sign. hello = "Hello there" We indent the definitions of functions. We invoke this function like this: hello
  • 15. Arguments Functions can have arguments square number = number * number Call it as square 2 They have explicit returns.
  • 16. Multiple Arguments Multiple arguments use spaces: add number1 number2 = number1 + number2 Call it as add 1 2 Woah.... no commas!
  • 17. Type annotations We can enforce data types for our functions so Elm can help us out. functionName: TypeOfArg1-> TypeOfArg2 -> TypeOfArg3 -> ReturnType
  • 18. Annotation Examples: No parameters. Just return value hello: String hello = "Hello there" Two parameters and a return value add: Float -> Float -> Float add number1 number2 = number1 + number2
  • 19. Modules Define modules to group your code. module Hello where main = -- something goes here
  • 20. Html functions The elm-html module exposes many functions for building up virtual DOM nodes. The main function can render HTML if the HTML module is included. import Html exposing(p, text) main = p [] [text "Hello World"]
  • 21. p and text p [] [text "Hello World"] p and text are two functions from elm-html p takes two lists ā€¢ a list of attributes (can be empty) ā€¢ a list of child elements text takes a string of text to display.
  • 22. HTML functions are uniform. Each takes attributes and elements. So we can nest them like HTML. div [class "foo", id "bar" ] [ h1 [] [text "Hello"], p [] [text "World"] ] There's a function for every element. Just be sure to expose what you use.
  • 23. Seriously uniform label [for "name"] [text "Name"] input [id "name", type' "number", step "any"] [] Even functions for tags that don't allow inner content still take two lists as arguments.
  • 24. Html Modules ā€¢ Html contains all the tags ā€¢ Html.Attributes contains the attributes (like class, id, href, etc) ā€¢ Html.Events contains events like onClick
  • 25. Html Attributes import Html exposing(Html, div, text, p) import Html.Attributes exposing(class) main = div [class "wrapper"] [ p [class "notice"] [text "This is important!"] ]
  • 26. Composability main = view view: Html view = div [] [ p [] [ text "Hello ", em [] [text "world"] ] ]
  • 27. Resuability main = div [] [ view "Hello", view "Goodbye" ] view: String -> Html view word = div [] [ p [] [ text (word ++ " "), em [] [text "world"] ] ]
  • 28. Web Interfaces import Html exposing(Html, Attribute, p, text) import Html.Attributes exposing(style) elementStyle: Attribute elementStyle = style [ ("color", "red") , ("font-size", "2em") ] main: Html main = view view = p [elementStyle] [text "Hello World"]
  • 29. Helpers! ļ¬eldWithLabel: String -> String -> String -> Html ļ¬eldWithLabel ļ¬eldID ļ¬eldName ļ¬eldType = div [] [ label [for ļ¬eldID] [text ļ¬eldName], input [ id ļ¬eldID, type' ļ¬eldType] [] ]
  • 30. Build Out The Helpers numberField: String -> String -> Html numberField ļ¬eldID ļ¬eldName = ļ¬eldWithLabel ļ¬eldID ļ¬eldName "number" textField: String -> String -> Html textField ļ¬eldID ļ¬eldName = ļ¬eldWithLabel ļ¬eldID ļ¬eldName "text" emailField: String -> String -> Html emailField ļ¬eldID ļ¬eldName = ļ¬eldWithLabel ļ¬eldID ļ¬eldName "email"
  • 31. Shiny Happy Frontend Code main: Html main = div [] [ textField "name" "Name", numberField "age" "Age", emailField "email" "Email" ]
  • 32. Elm Architecture View: Function that fires when model changes. Transofms a model into the UI that people see. Model: Something that holds the current state of the app. No behavior. Just the state. No behavior. This is not MVC with objects! Update: Function that fires when state changes. Always returns a new model.
  • 33. Signals and Mailboxes Signals Signals route messages around the application. Pressing a button is a signal. We can send data along signals. Mailboxes Mailboxes receive signals and send signals. A mailbox has an address and a signal to respond to.
  • 34. Basic Flow ā€¢ Model is initialized ā€¢ View is displayed with model ā€¢ Events send Signals to Mailboxes ā€¢ Mailboxes trigger updates ā€¢ New model is created ā€¢ New view is rendered Yikes!
  • 35. Elm StartApp.Simple Like Flux, without all the code. ā€¢ Define Actions ā€¢ Define a model to represent data ā€¢ Define a view function ā€¢ Define an update function that returns a new model.
  • 36. Change Text On Click import Html exposing (Html, text, h1, p, div, button) import StartApp.Simple as StartApp import Html.Events exposing (onClick) main = StartApp.start {model = "Hello ", view = view, update = update} view address initialText = div [] [ h1 [] [text "Events"], p [] [ text initialText ], button [onClick address "change"] [text "Push me"] ] update action model = "it changed"
  • 37. Actions Actions get sent to the Update. type Action = Increment | Decrement model = 0 update: Signal.Action -> Int -> Int update action model = case action of Increment -> model + 1 Decrement -> model - 1
  • 38. Multiple events main = StartApp.start { model = model, view = view, update = update } view: Signal.Address Action -> Int -> Html view address model = div [] [ button [ onClick address Increment ] [ text "Up" ] , span [] [ text (toString model) ] , button [ onClick address Decrement ] [ text "Down" ] ]
  • 39. Once again... ā€¢ StartApp renders the view using an initial model state. ā€¢ Events defined in the view send Actions to Signal Addresses which route to update. ā€¢ update returns a new version of the model ā€¢ StartApp causes the view to be rendered whenever model changes.
  • 40. Calculator Compound Interest Calculator Write a program to compute the value of an investment compounded over time. The program should ask for the starting amount, the number of years to invest, the interest rate, and the number of periods per year to compound.
  • 41. Project setup Create folder and file to work in $ mkdir calculator && cd calculator $ touch calculator.elm Init the project $ elm package install Install HTML and StartApp dependencies. $ elm package install evancz/elm-html $ elm package install evancz/start-app
  • 42. Livereloading Make browser reload when we save $ npm install -g elm-live $ elm-live calculator.elm
  • 43. Steps ā€¢ Create the basic app ā€¢ Build the form ā€¢ Bind form to model and define events ā€¢ Perform calculations ā€¢ Display Output
  • 44. The Basic App import Html exposing (Html, text, h1, p, div, button, label, input) import Html.Attributes exposing ( style, for, id, step, type', value) import StartApp.Simple as StartApp import Html.Events exposing (onClick) main = StartApp.start {model = model, view = view, update = update}
  • 45. Define a model and update model: Float model = 0 update: String -> Float -> Float update action model = model
  • 46. Building the form ā€¢ Use label, input functions ā€¢ Use number fields ā€¢ Each field change updates model state ā€¢ Clicking button calculates new amount
  • 47. numberField helper numberField: String -> String -> Html numberField ļ¬eldID ļ¬eldName = div [] [ label [for ļ¬eldID] [text ļ¬eldName], input [ id ļ¬eldID, type' "number", step "any"] [] ]
  • 48. Style the form labelStyle: Attribute labelStyle = style [ ("width", "200px") , ("padding", "10px") , ("text-align", "right") , ("display", "inline-block") ]
  • 49. Apply style to field div [] [ label [labelStyle, for ļ¬eldID] [text ļ¬eldName], input [ id ļ¬eldID, type' "number", step "any"] [] ]
  • 50. Build the View view: Signal.Address String -> Float -> Html view address model = div [] [ h1 [] [text "Calculator"], div [] [ numberField "principal" "Principal", numberField "rate" "Rate", numberField "years" "Periods", numberField "years" "Years" ] button [onClick address "calculate"] [text "Calculate"] ]
  • 51. Define Our Actions type Action = NoOp | SetPrinciple String | SetPeriods String | SetRate String | SetYears String | Calculate
  • 52. Define A Model type alias Model = { principle: String , rate: String , years: String , periods: String , newAmount: Float} model: Model model = { principle = "1500.00" , rate = "4.3" , years = "6" , periods = "4" , newAmount = 0 }
  • 53. Pass address, action, and model data to fields view: Signal.Address Action -> Model -> Html view address model = div [] [ h1 [] [text "Calculator"], div [] [ numberField address SetPrinciple "principle" "Principle" model.principle, numberField address SetRate "rate" "Rate" model.rate, numberField address SetPeriods "periods" "Periods" model.periods, numberField address SetYears "years" "Years" model.years ], button [onClick address Calculate] [text "Click me"],
  • 54. Add Events To Form using Actions and model data numberField: Signal.Address Action -> (String -> Action) -> String -> String -> String -> Html numberField address action ļ¬eldID name ļ¬eldValue = div [] [ label [labelStyle, for ļ¬eldID] [text name], input [id ļ¬eldID, type' "number", step "any", on "input" targetValue (Signal.message address << action ), value ļ¬eldValue] [] ]
  • 55. Update model from form update: Action -> Model -> Model update action model = case action of NoOp -> model SetPrinciple p -> {model | principle = p} SetRate r -> {model | rate = r} SetYears y -> {model | years = y} SetPeriods p -> {model | periods = p} Calculate -> calculateNewAmount model
  • 56. The program Logic compoundInterest: Float -> Float -> Float -> Float -> Float compoundInterest principle rate periods years = (principle * (1 + (rate / periods ) ) ^ (years * periods) )
  • 57. Converting Strings To Floats convertToFloat: String -> Float convertToFloat string = case String.toFloat string of Ok n -> n Err _ -> 0.0
  • 58. Implement CalculateNewAmount calculateNewAmount: Model -> Model calculateNewAmount model = let rate = convertToFloat model.rate / 100 years = convertToFloat model.years principle = convertToFloat model.principle periods = convertToFloat model.periods in {model | newAmount = (compoundInterest principle rate periods years) }
  • 59. Display the Output output: Model -> Html output model = div [] [ span [] [text "Amount: "], span [] [text (toString model.newAmount) ] ] And add it to the view.
  • 60. Discuss What are your thoughts? Is this cool? Good? Bad? A terrible idea or the greatest thing ever?
  • 61. Issues 1. Tons of code to do simple things 2. Integration with external services is complex 3. Must re-learn a lot of things about web development 4. Small community
  • 62. Benefits 1. Small community 2. Benefits of React with a clear opinionated approach 3. Fantastic error messages 4. Types ensure data integrity and flow
  • 63. Write code ā€¢ Elm website: http://elm-lang.org/ ā€¢ Try Elm http://elm-lang.org/try ā€¢ Package system: http://package.elm- lang.org/ ā€¢ Documentation http://elm-lang.org/docs
  • 64. Where to go next? Book: http://pragprog.com/titles/bhwb Twitter: @bphogan Material: http://bphogan.com/ presentations/elm2016/ Thank you! Ā© Brian Hogan, 2016. Photos from http://pexels.com