The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming...

27
The Elm Programming Language Richard Townsend Advanced Topics in Programming Languages and Compilers

Transcript of The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming...

Page 1: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

The Elm Programming LanguageRichard Townsend

Advanced Topics in Programming Languages and Compilers

Page 2: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Where did Elm come from?

Evan Czaplicki

Page 3: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Where did Elm come from?

● Frustrated with GUI design

Evan Czaplicki

Page 4: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Where did Elm come from?

● Frustrated with GUI design

● Use declarative approach

Evan Czaplicki

Page 5: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Where did Elm come from?

● Frustrated with GUI design

● Use declarative approach

● Want responsive GUIs

Evan Czaplicki

Page 6: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Functional Reactive Programming

Page 7: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Functional Reactive Programming

ReactivePure Functional

Page 8: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Functional Reactive Programming

ReactivePure Functional

● Computation = Functions

● No side effects

Page 9: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Functional Reactive Programming

Reactive

● Computation = Data flows

● Side effects run the program

Pure Functional

● Computation = Functions

● No side effects

Page 10: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Functional Reactive Programming

Reactive

● Computation = Data flows

● Side effects run the program

Pure Functional

● Computation = Functions

● No side effects

How do we get both?

Page 11: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Signals: Time-Varying Values

Page 12: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Signals: Time-Varying Values

Page 13: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Signals: Time-Varying Values

Page 14: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Signals: Time-Varying Values

Page 15: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

The main idea

Everything is a pure expression…unless you use Signals.

Page 16: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

The main idea

Elm’s Idea: 1. Pure expressions -> layout of GUI

Page 17: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

The main idea

Elm’s Idea: 1. Pure expressions -> layout of GUI

2. Signals -> react to real-world events

Page 18: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

The main idea

Elm’s Idea: 1. Pure expressions -> layout of GUI

2. Signals -> react to real-world events

3. lift and foldp -> update layout dynamically

Page 19: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Elm in Action: GUI Layoutcontent : [Element]content = [ plainText "Bears, Oh My!" , image 200 200 "/yogi.jpg" , asText (reverse [1..9]) ]

main : Elementmain = flow down content

[9,8,7,6,5,4,3,2,1]

Page 20: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Elm in Action: Signals

import Mouse

resizeableYogi : Int -> ElementresizeableYogi n = image n n "/yogi.jpg"

edgeLength : Signal IntedgeLength = lift (\(x,y) -> max x y) Mouse.position

main : Signal Elementmain = lift resizeableYogi edgeLength

Page 21: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Elm in Action: Mix N’ Match

Page 22: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Current Compiler http://elm-lang.org/

● Elm-to-Javascript compiler○ With HTML and CSS too○ Can generate JS file

Page 23: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Current Compiler http://elm-lang.org/

● Elm-to-Javascript compiler○ With HTML and CSS too○ Can generate JS file

● Advantages○ Complex graphics are possible○ “unmatched cross-platform support”

Czaplicki, Evan, and Stephen Chong. "Asynchronous Functional Reactive Programming for GUIs." Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (2013): 411-22. Print.

Page 24: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Current Compiler http://elm-lang.org/

● Elm-to-Javascript compiler○ With HTML and CSS too○ Can generate JS file

● Advantages○ Complex graphics are possible○ “unmatched cross-platform support”

● Disadvantages○ Issues with concurrency○ Slow program execution

Czaplicki, Evan, and Stephen Chong. "Asynchronous Functional Reactive Programming for GUIs." Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (2013): 411-22. Print.

Page 25: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Conclusions

● Elm is pretty awesome!○ functional○ web programming scares you

Programming Isn't Scary. Digital image. Impatient Designer. N.p., n.d. Web. 25 Sept. 2014.

Page 26: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

Conclusions

● Elm is pretty awesome!○ functional○ web programming scares you

● Still growing!○ production continues at Prezi○ time-traveling debugger

Programming Isn't Scary. Digital image. Impatient Designer. N.p., n.d. Web. 25 Sept. 2014.

Page 27: The Elm Programming Languageaho/cs6998/Lectures/14-09-29... · 2014-10-01 · The Elm Programming Language Richard Townsend ... Elm-to-Javascript compiler With HTML and CSS too Can

ReferencesCzaplicki, Evan, and Stephen Chong. "Asynchronous Functional Reactive Programming for GUIs." Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (2013): 411-22. Print.

Czaplicki, Evan. "Elm." Elm. N.p., n.d. Web. 28 Sept. 2014. <http://elm-lang.org>.

Czaplicki, Evan. "Functional Reactive Programming in Elm." Strange Loop. 5 Nov. 2013. InfoQ. Web. 28 Sept. 2014.