SlideShare a Scribd company logo
1 of 33
Download to read offline
Elm 0.17
Michael Twomey @ Elm Dublin May 2016
https://github.com/micktwomey/
elm-0.17-dublin-elm-may-2016
What is Elm?
Really Short Introduction
Elm is a functional language that compiles to
JavaScript.
Noted for helpful compiler errors.
ML style language.
Basic Example
(Pardon the formatting to
fit)
import Html
import Html.App
main = Html.App.beginnerProgram
{ model = model
, update = update
, view = view }
type alias Model = { message : String}
model = { message = "Hello World!" }
type Msg = Nothing
update msg model = model
view model = Html.h1 [] [ Html.text model.message ]
The Pattern
1. Model
2. Update
3. View
(AKA Redux in ReactJS land)
What's New in
0.17?
No More Signals !
foldp and mailboxes are gone too
Subscriptions are the new hotness
Subscription
Example
import Html
import Html.App
import Time
main = Html.App.program
{ init = init, update = update , view = view
, subscriptions = subscriptions
}
type alias Model = { time : Time.Time}
init = ( { time = 0 }, Cmd.none)
type Msg = Tick Time.Time
update msg model =
case msg of
Tick newTime -> ( { model | time = newTime } , Cmd.none)
subscriptions : Model -> Sub Msg
subscriptions model = Time.every Time.second Tick
view model = Html.h1 [] [ Html.text ("The time is " ++ toString model.time) ]
Just the Subscription Bits
main = Html.App.program
{ ...
, subscriptions = subscriptions }
subscriptions : Model -> Sub Msg
subscriptions model =
Time.every Time.second Tick
update : Msg -> Model -> Model
update msg model =
case msg of
Tick newTime -> ...
SomeActionFromUser -> ...
SVG Version
(from Elm docs)
main = Html.App.program
{ init = init, update = update , view = view
, subscriptions = subscriptions }
type alias Model = Time.Time
init = ( 0 , Cmd.none)
update msg model =
case msg of
Tick newTime -> ( newTime , Cmd.none)
type Msg = Tick Time.Time
subscriptions model = Time.every Time.second Tick
view model =
let
angle = turns (Time.inMinutes model)
handX = toString (50 + 40 * cos angle)
handY = toString (50 + 40 * sin angle)
in
svg [ viewBox "0 0 100 100", width "300px" ]
[ circle [ cx "50", cy "50", r "45", fill "#0B79CE" ] []
, line [ x1 "50", y1 "50", x2 handX, y2 handY, stroke "#023963" ] []
]
The only difference is the view
-- HTML
view model =
Html.h1 [] [ Html.text ("The time is " ++ toString model.time) ]
-- SVG
view model =
let
angle = turns (Time.inMinutes model)
handX = toString (50 + 40 * cos angle)
handY = toString (50 + 40 * sin angle)
in
svg [ viewBox "0 0 100 100", width "300px" ]
[ circle [ cx "50", cy "50", r "45", fill "#0B79CE" ] []
, line [ x1 "50", y1 "50", x2 handX, y2 handY, stroke "#023963" ] []
]
More 0.17
Changes
No more Signal.Address (simpler code)
-- 0.16
view : Signal.Address Action -> Model -> Html
view address model =
div []
[ button [ onClick address Decrement ] [ text "-" ]
, div [ countStyle ] [ text (toString model) ]
, button [ onClick address Increment ] [ text "+" ]
]
-- 0.17
view : Model -> Html Msg
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [ countStyle ] [ text (toString model) ]
, button [ onClick Increment ] [ text "+" ]
]
→ Effects are now Cmd
→ Action is now Msg
→ StartApp is now Html.App
→ Many packages moved into core
→ Graphics.* now lives in evancz/elm-graphics
Msg Example
(clicking
buttons)
type Msg
= SayHello
| SayGoodbye
update msg model =
case msg of
SayHello ->
{ model | message = "Hello there!" }
SayGoodbye ->
{ model | message = "Goodbye!" }
view model =
Html.div []
[ Html.button [ Html.Events.onClick SayHello ] [ Html.text "Say Hello!" ]
, Html.button [ Html.Events.onClick SayGoodbye ] [ Html.text "Say Goodbye!" ]
, Html.h1 [] [ Html.text model.message ]
]
Effect Managers Added
Moves the hard work to the library author
Example: Web Sockets
Simple API
WebSocket.send "ws://echo.websocket.org" input
WebSocket.listen "ws://echo.websocket.org" NewMessage
(Effect manager handles connection management,
errors, re-connecting for you.)
Websocket Example
import Html exposing (Html, div, text)
import Html.App as Html
import WebSocket
main = Html.program
{ init = init, view = view
, update = update, subscriptions = subscriptions }
echoServer = "ws://echo.websocket.org"
type alias Model =
{ input : String , messages : List String }
init = ( Model "" [], WebSocket.send echoServer "Hello" )
type Msg = NewMessage String
update msg {input, messages} =
case msg of
NewMessage str -> (Model input (str :: messages), Cmd.none)
subscriptions model =
WebSocket.listen echoServer NewMessage
view model =
div [] (List.map viewMessage (List.reverse model.messages))
viewMessage msg = Html.p [] [ text msg ]
Graphics Demoted to
External library
!
HTML app first, with possible embedded Graphics.
Html.toElement is now Element.toHtml.
No more Graphics.Input (use HTML forms).
import Color
import Html
import Html.App
import Element
import Collage exposing (..)
main =
Html.App.beginnerProgram { model = model, update = update, view = view }
type alias Model = String
model = "Hello"
type Msg = Nothing
update msg model =
model
view model =
Html.div []
[ collage 320 200
[ group
[ circle 50 |> filled Color.charcoal
, circle 40 |> filled Color.yellow
]
] |> Element.toHtml
]
-- 0.16
view : Model -> Element
view reading =
collage 320 200
[ group
[ circle 50 |> filled Color.charcoal
, circle 40 |> filled Color.yellow
]
]
-- 0.17
view : Model -> Html Msg
view model =
Html.div []
[ collage 320 200
[ group
[ circle 50 |> filled Color.charcoal
, circle 40 |> filled Color.yellow
]
] |> Element.toHtml
]
Graphics Clock Example
Html.div []
[ collage 640
480
[ group
[ circle 150 |> filled Color.darkBlue
, path
[ ( 0, 0 )
, ( handX, handY )
]
|> traced
{ defaultLine
| width = 5
, color = Color.darkCharcoal
}
]
]
|> toHtml
, Html.h1 [] [ Html.text ("The time is " ++ time) ]
]
http://elm-lang.org/blog/farewell-to-frp
http://guide.elm-lang.org
http://www.lambdacat.com/migrating-from-
elm-0-16-to-0-17-from-startapp/
http://noredink.github.io/posts/
signalsmigration.html
https://github.com/micktwomey/elm-0.17-dublin-
elm-may-2016

More Related Content

What's hot

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
 
Elixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsElixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsBrooklyn Zelenka
 
Dynamic HTML Event Model
Dynamic HTML Event ModelDynamic HTML Event Model
Dynamic HTML Event ModelReem Alattas
 
Haxe: What Makes It Cool
Haxe: What Makes It CoolHaxe: What Makes It Cool
Haxe: What Makes It CooleddieSullivan
 
Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)Jens Ravens
 
Introduction tomongodb
Introduction tomongodbIntroduction tomongodb
Introduction tomongodbLee Theobald
 
Decompiladores
DecompiladoresDecompiladores
Decompiladoresreivax2091
 
An afternoon with angular 2
An afternoon with angular 2An afternoon with angular 2
An afternoon with angular 2Mike Melusky
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...Codemotion
 
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming JobsMonoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming JobsRyan Weald
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoRyan Weaver
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Jalpesh Vasa
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellSalaudeen Rajack
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptjnewmanux
 

What's hot (20)

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)
 
PHP-Part3
PHP-Part3PHP-Part3
PHP-Part3
 
Elixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsElixir and Phoenix for Rubyists
Elixir and Phoenix for Rubyists
 
PHP-Part2
PHP-Part2PHP-Part2
PHP-Part2
 
Dynamic HTML Event Model
Dynamic HTML Event ModelDynamic HTML Event Model
Dynamic HTML Event Model
 
Haxe: What Makes It Cool
Haxe: What Makes It CoolHaxe: What Makes It Cool
Haxe: What Makes It Cool
 
Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)
 
Introduction tomongodb
Introduction tomongodbIntroduction tomongodb
Introduction tomongodb
 
Decompiladores
DecompiladoresDecompiladores
Decompiladores
 
Protocol-Oriented MVVM
Protocol-Oriented MVVMProtocol-Oriented MVVM
Protocol-Oriented MVVM
 
An afternoon with angular 2
An afternoon with angular 2An afternoon with angular 2
An afternoon with angular 2
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming JobsMonoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
Monoids, Store, and Dependency Injection - Abstractions for Spark Streaming Jobs
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 

Similar to Elm 0.17 at Dublin Elm Meetup May 2016

Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With ElmBrian Hogan
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With ElmBrian Hogan
 
dotnetConf2019 meetup in AICHI / Elmish
dotnetConf2019 meetup in AICHI / ElmishdotnetConf2019 meetup in AICHI / Elmish
dotnetConf2019 meetup in AICHI / ElmishMidoliy
 
Please, correct the following ELM codemodule Main exposing (..).pdf
Please, correct the following ELM codemodule Main exposing (..).pdfPlease, correct the following ELM codemodule Main exposing (..).pdf
Please, correct the following ELM codemodule Main exposing (..).pdfagarshailenterprises
 
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
 
Model-View-Update, and Beyond!
Model-View-Update, and Beyond!Model-View-Update, and Beyond!
Model-View-Update, and Beyond!Simon Fowler
 
TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08Andy Gelme
 
Scripting languages
Scripting languagesScripting languages
Scripting languagesteach4uin
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponentsMartin Hochel
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeRamon Ribeiro Rabello
 
Aspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csAspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csMurali G
 
MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2Naji El Kotob
 

Similar to Elm 0.17 at Dublin Elm Meetup May 2016 (20)

Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With Elm
 
Elm intro
Elm introElm intro
Elm intro
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With Elm
 
dotnetConf2019 meetup in AICHI / Elmish
dotnetConf2019 meetup in AICHI / ElmishdotnetConf2019 meetup in AICHI / Elmish
dotnetConf2019 meetup in AICHI / Elmish
 
A proper introduction to Elm
A proper introduction to ElmA proper introduction to Elm
A proper introduction to Elm
 
Please, correct the following ELM codemodule Main exposing (..).pdf
Please, correct the following ELM codemodule Main exposing (..).pdfPlease, correct the following ELM codemodule Main exposing (..).pdf
Please, correct the following ELM codemodule Main exposing (..).pdf
 
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
 
Model-View-Update, and Beyond!
Model-View-Update, and Beyond!Model-View-Update, and Beyond!
Model-View-Update, and Beyond!
 
Learning Svelte
Learning SvelteLearning Svelte
Learning Svelte
 
TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08
 
Lecture one
Lecture oneLecture one
Lecture one
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
forms
formsforms
forms
 
forms
formsforms
forms
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
Aspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csAspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_cs
 
Html css
Html cssHtml css
Html css
 
MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2
 

Recently uploaded

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Elm 0.17 at Dublin Elm Meetup May 2016

  • 1. Elm 0.17 Michael Twomey @ Elm Dublin May 2016 https://github.com/micktwomey/ elm-0.17-dublin-elm-may-2016
  • 3. Really Short Introduction Elm is a functional language that compiles to JavaScript. Noted for helpful compiler errors. ML style language.
  • 4. Basic Example (Pardon the formatting to fit)
  • 5. import Html import Html.App main = Html.App.beginnerProgram { model = model , update = update , view = view } type alias Model = { message : String} model = { message = "Hello World!" } type Msg = Nothing update msg model = model view model = Html.h1 [] [ Html.text model.message ]
  • 6. The Pattern 1. Model 2. Update 3. View (AKA Redux in ReactJS land)
  • 8. No More Signals ! foldp and mailboxes are gone too Subscriptions are the new hotness
  • 10. import Html import Html.App import Time main = Html.App.program { init = init, update = update , view = view , subscriptions = subscriptions } type alias Model = { time : Time.Time} init = ( { time = 0 }, Cmd.none) type Msg = Tick Time.Time update msg model = case msg of Tick newTime -> ( { model | time = newTime } , Cmd.none) subscriptions : Model -> Sub Msg subscriptions model = Time.every Time.second Tick view model = Html.h1 [] [ Html.text ("The time is " ++ toString model.time) ]
  • 12. main = Html.App.program { ... , subscriptions = subscriptions } subscriptions : Model -> Sub Msg subscriptions model = Time.every Time.second Tick update : Msg -> Model -> Model update msg model = case msg of Tick newTime -> ... SomeActionFromUser -> ...
  • 14. main = Html.App.program { init = init, update = update , view = view , subscriptions = subscriptions } type alias Model = Time.Time init = ( 0 , Cmd.none) update msg model = case msg of Tick newTime -> ( newTime , Cmd.none) type Msg = Tick Time.Time subscriptions model = Time.every Time.second Tick view model = let angle = turns (Time.inMinutes model) handX = toString (50 + 40 * cos angle) handY = toString (50 + 40 * sin angle) in svg [ viewBox "0 0 100 100", width "300px" ] [ circle [ cx "50", cy "50", r "45", fill "#0B79CE" ] [] , line [ x1 "50", y1 "50", x2 handX, y2 handY, stroke "#023963" ] [] ]
  • 15. The only difference is the view
  • 16. -- HTML view model = Html.h1 [] [ Html.text ("The time is " ++ toString model.time) ] -- SVG view model = let angle = turns (Time.inMinutes model) handX = toString (50 + 40 * cos angle) handY = toString (50 + 40 * sin angle) in svg [ viewBox "0 0 100 100", width "300px" ] [ circle [ cx "50", cy "50", r "45", fill "#0B79CE" ] [] , line [ x1 "50", y1 "50", x2 handX, y2 handY, stroke "#023963" ] [] ]
  • 18. No more Signal.Address (simpler code) -- 0.16 view : Signal.Address Action -> Model -> Html view address model = div [] [ button [ onClick address Decrement ] [ text "-" ] , div [ countStyle ] [ text (toString model) ] , button [ onClick address Increment ] [ text "+" ] ] -- 0.17 view : Model -> Html Msg view model = div [] [ button [ onClick Decrement ] [ text "-" ] , div [ countStyle ] [ text (toString model) ] , button [ onClick Increment ] [ text "+" ] ]
  • 19. → Effects are now Cmd → Action is now Msg → StartApp is now Html.App → Many packages moved into core → Graphics.* now lives in evancz/elm-graphics
  • 21. type Msg = SayHello | SayGoodbye update msg model = case msg of SayHello -> { model | message = "Hello there!" } SayGoodbye -> { model | message = "Goodbye!" } view model = Html.div [] [ Html.button [ Html.Events.onClick SayHello ] [ Html.text "Say Hello!" ] , Html.button [ Html.Events.onClick SayGoodbye ] [ Html.text "Say Goodbye!" ] , Html.h1 [] [ Html.text model.message ] ]
  • 22. Effect Managers Added Moves the hard work to the library author
  • 24. Simple API WebSocket.send "ws://echo.websocket.org" input WebSocket.listen "ws://echo.websocket.org" NewMessage (Effect manager handles connection management, errors, re-connecting for you.)
  • 26. import Html exposing (Html, div, text) import Html.App as Html import WebSocket main = Html.program { init = init, view = view , update = update, subscriptions = subscriptions } echoServer = "ws://echo.websocket.org" type alias Model = { input : String , messages : List String } init = ( Model "" [], WebSocket.send echoServer "Hello" ) type Msg = NewMessage String update msg {input, messages} = case msg of NewMessage str -> (Model input (str :: messages), Cmd.none) subscriptions model = WebSocket.listen echoServer NewMessage view model = div [] (List.map viewMessage (List.reverse model.messages)) viewMessage msg = Html.p [] [ text msg ]
  • 28. HTML app first, with possible embedded Graphics. Html.toElement is now Element.toHtml. No more Graphics.Input (use HTML forms).
  • 29. import Color import Html import Html.App import Element import Collage exposing (..) main = Html.App.beginnerProgram { model = model, update = update, view = view } type alias Model = String model = "Hello" type Msg = Nothing update msg model = model view model = Html.div [] [ collage 320 200 [ group [ circle 50 |> filled Color.charcoal , circle 40 |> filled Color.yellow ] ] |> Element.toHtml ]
  • 30. -- 0.16 view : Model -> Element view reading = collage 320 200 [ group [ circle 50 |> filled Color.charcoal , circle 40 |> filled Color.yellow ] ] -- 0.17 view : Model -> Html Msg view model = Html.div [] [ collage 320 200 [ group [ circle 50 |> filled Color.charcoal , circle 40 |> filled Color.yellow ] ] |> Element.toHtml ]
  • 32. Html.div [] [ collage 640 480 [ group [ circle 150 |> filled Color.darkBlue , path [ ( 0, 0 ) , ( handX, handY ) ] |> traced { defaultLine | width = 5 , color = Color.darkCharcoal } ] ] |> toHtml , Html.h1 [] [ Html.text ("The time is " ++ time) ] ]