SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Downloaden Sie, um offline zu lesen
Luca Mugnaini
Functional Programming
and Elm
Functional Programming
Originated from lambda calculus developed in
the 1930s by Alonzo Church
What is Functional Programming?
Programming with
mathematical functions*
*It doesn’t mean you need to know math
• Do this, then do that
• Any effect (Unsafe)
• Commands (statements)
• Control Flow
• Name of a location
Imperative
• No notion of sequence
• Limited effect (Safe)
• Expressions
• Data Flow
• Name of a value
vs. Functional
f : a à World à (World, b)
If there are no side-effects, how can
we change the state of the world?
f... takes in the state of the
world and returns a new
world, thus remaining pure
No Side-effects
update : Msg à Model à ( Model, Cmd Msg )
https://channel9.msdn.com/Shows/Going+Deep/Erik-Meijer-Functional-Programming
Functional-flavored
• Lisp 1958 (Scheme, Clojure,
Racket)
• ML ”Lisp with types” =>
Ocaml (F#, Scala, Reason)
• Erlang (Elixir)
• Javascript, Java 8, Kotlin,
Perl, Python, PHP, etc.
Functional-first, Pure
• Haskell (Elm)
Nirvana
“Haskell is useless”
Simon Peyton Jones
Honesty/Dishonesty
Erik Meijer
https://www.youtube.com/watch?v=iSmkqocn0oQ&t=22s
https://www.youtube.com/watch?v=z0N1aZ6SnBk&t=533
https://www.infoq.com/presentations/Taming-Effect-Simon-Peyton-Jones
Web Development
Web Development Fatigue3
Javascript fatigue +
CSS fatigue +
Framework/Npm fatigue =
Web
Development
Fatigue
What if I told you
Front-end can be done
without Javascript, HTML, CSS?
Elm
● Pure Functional Language
● Compiles to Javascript
● Statically typed + inferred
● Support Immutability and Currying
● Virtual DOM
What is Elm?
● Designed by Evan Czaplicki
● April 2012: Version 0.1
● August 2018: Latest version 0.19
● Stable (21 months since 0.18)
● Community in elmlang.slack.com
History
● No loops (“i = i + 1” doesn’t compile)
● No “null” and no “undefined”
● No “return”, everything is an expression
● “if” always need “else”
● No “this”, no callbacks, no closures, no hoisting
● No automatic type conversion
● JSON decoder/encoder instead of stringify/parse
Differences with Javascript
Javascript Elm
npm / yarn Built in
React / Angular / Vue
Flux / Redux / MobX
Built in
Built in
Immutable.js
Typescript / Flow
Built in
Built in
Without HTML, CSS: elm-ui
row [ padding 10, spacing 7 ]
[ el [] none
, el [] none
, el [] none
]
spacing : Distance between children
padding : Parent Padding
[ centerX
, centerY
]
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform:
translate(-50%, -50%);
}
CSS elm-ui
No more CSS tricks
10
nice
things
about
Elm
Nice thing #1
Helpful, friendly errors
Nice thing #2
No runtime exceptions
Nice thing #3
Performance
Nice thing #4
Enforced Semantic
Nice thing #5
Time-travelling debugger
Nice thing #6
Type inference
Nice thing #7
elm-format
Nice thing #8
Demystify FP concepts
Functors
Monads Category Theory
Algebraic Data Type
The Elm Architecture is a simple pattern for
architecting webapps. It is made of thee parts
Nice thing #9
The Elm Architecture (TEA)
Model the state of your application
View a way to view your state as HTML
Update a way to update your state
28
Cartoon cute unicorns vectors design by loutpany from https://freedesignfile.com
Safe AreaUnsafe Area
Elm Runtime
DOM
MsgModel
Model
Model
Html
Model
New!
Effects
http requests,
ports Cmd
EventEvent!
New!
New!
Cmd
DOM
Html
EventEvent!
update
view
[1,2] + [3,4] = ?
[1,2] + [3,4] = ?
Error [1,2,3,4]
[4,6] “1,23,4”
A B
C D
"1,23,4"
Javascript Elm
-- TYPE MISMATCH ---------------------
I cannot do addition with lists:
[1,2] + [3,4]
^^^^^
The left side of (+) is a list of type:
List number
But (+) only works with Int and Float
values.
Hint: Switch to the (++) operator to
append lists!
[1,2] + [3,4] = ?
What can go wrong with
automatic type conversion?
https://itnext.io/things-that-can-go-wrong-without-a-strictly-typed-language-d91d418a53a1
“If you want user input to be automatically typecast as a
number, you can add the number modifier to your v-
model managed inputs”
<input type="number" v-model="product.quantity">
<input type="number" v-model.number="product.quantity">
totalProducts() {
return this.products.reduce((sum, product) => {
return sum + product.quantity
}, 0)
}
totalProducts() {
return this.products.reduce((sum, product) => {
if (typeof product.quantity === "number") {
return sum + product.quantity;
} else {
return sum;
}
}, 0)
}
<button @click="product.quantity += 1">
<button @click="product.quantity = Number(product.quantity) + 1">
Now it works but...
type alias Product =
{ id : Int
, quantity : Int
, name : String
}
changeQuantity : Product -> String -> Product
changeQuantity product newQuantity =
{ product
| quantity =
Maybe.withDefault product.quantity
(String.toInt newQuantity)
}
“If the user typed a valid number, replace the old number with the
new one, otherwise keep the old number”
Typos <input v-model.number="product.quanity">
t
Elm
Fail silently
Input fields are
empty but buttons
work.
-- TYPE MISMATCH --------------------
The 2nd argument to `map` is not what I
expect:
84| products
^^^^^^^^
This `products` value is a:
List Product
But `map` needs the 2nd argument to be:
List { a | id : Int, name : String, quanity
: Int, quantity : Int }
Hint: Seems like a record field typo. Maybe
quanity should be quantity?
Vue
C de
module Main exposing (main)
import Html exposing (..)
import Html.Attributes exposing (..)
main =
div []
[ button [id "counter"] [ text "+1" ]
, div [] [ text <| String.fromInt 0 ]
, button [] [ text ”-1" ]
]
<div id="counter">
<button>+1</button>
<div>0</div>
<button>-1</button>
</div>
-- MODEL
type alias Model =
{ count : Int }
init : Model
init =
{ count = 0 }
-- UPDATE
type Msg
= Increment
| Decrement
update : Msg -> Model -> Model
update msg model =
case msg of
Increment ->
{ model | count = model.count + 1 }
Decrement ->
{ model | count = model.count - 1 }
-- VIEW
view : Model -> Html Msg
view model =
layout [] <|
column []
[ button []
{ onPress = Just Increment
, label = text "+1"
}
, el [] <|
text (String.fromInt model.count)
, button []
{ onPress = Just Decrement
, label = text "-1"
}
]
main : Program () Model Msg
main =
Browser.sandbox
{ init = init
, view = view
, update = update
}
Examples
ellie-app.comhttps://ellie-app.com/4ddCRdyx4Rta1
www.nsb.no
unsoundscapes.itch.io/cubik
malax.github.io/elmboy
● The ideas of Functional Programming are
becoming mainstream (for a reason)
● Learning Elm will make you a better [Javascript,
React, Angular, Vue, etc.] developer
● Writing pure code is an enjoyable experience
that make front-end development fun again!

Weitere ähnliche Inhalte

Was ist angesagt?

Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in pythonRaginiJain21
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4Shameer Ahmed Koya
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++Neeru Mittal
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional ProgrammingAndraž Bajt
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptxsandeep54552
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examplesgreatqadirgee4u
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principlesmoduledesign
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about lazinessJohan Tibell
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principlesmoduledesign
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Saket Pathak
 

Was ist angesagt? (20)

Loop Statements [5] M
Loop Statements [5] MLoop Statements [5] M
Loop Statements [5] M
 
GNU octave
GNU octaveGNU octave
GNU octave
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about laziness
 
Stack
StackStack
Stack
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
 
Queue
QueueQueue
Queue
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
A taste of Functional Programming
A taste of Functional ProgrammingA taste of Functional Programming
A taste of Functional Programming
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 

Ähnlich wie Functional programming and Elm

Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Scott Wlaschin
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional ProgrammingYuan Wang
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVAMuskanSony
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine LearningYounesCharfaoui
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)Spiros
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshopVinay Kumar
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme SwiftMovel
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2Mohamed Ahmed
 
.NET Foundation, Future of .NET and C#
.NET Foundation, Future of .NET and C#.NET Foundation, Future of .NET and C#
.NET Foundation, Future of .NET and C#Bertrand Le Roy
 
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Dadangsachir WANDA ir.mba
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programmingDhaval Dalal
 
Go Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional ProgrammingGo Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional ProgrammingLex Sheehan
 
London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010Skills Matter
 

Ähnlich wie Functional programming and Elm (20)

Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Functional go
Functional goFunctional go
Functional go
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine Learning
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Matlab-3.pptx
Matlab-3.pptxMatlab-3.pptx
Matlab-3.pptx
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
.NET Foundation, Future of .NET and C#
.NET Foundation, Future of .NET and C#.NET Foundation, Future of .NET and C#
.NET Foundation, Future of .NET and C#
 
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
 
Go Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional ProgrammingGo Beyond Higher Order Functions: A Journey into Functional Programming
Go Beyond Higher Order Functions: A Journey into Functional Programming
 
London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 

Mehr von Fangda Wang

[WWCode] How aware are you of your deciding model?
[WWCode] How aware are you of your deciding model?[WWCode] How aware are you of your deciding model?
[WWCode] How aware are you of your deciding model?Fangda Wang
 
Under the hood of architecture interviews at indeed
Under the hood of architecture interviews at indeedUnder the hood of architecture interviews at indeed
Under the hood of architecture interviews at indeedFangda Wang
 
How Indeed asks coding interview questions
How Indeed asks coding interview questionsHow Indeed asks coding interview questions
How Indeed asks coding interview questionsFangda Wang
 
Types are eating the world
Types are eating the worldTypes are eating the world
Types are eating the worldFangda Wang
 
From ic to tech lead
From ic to tech leadFrom ic to tech lead
From ic to tech leadFangda Wang
 
Introduction to japanese tokenizer
Introduction to japanese tokenizerIntroduction to japanese tokenizer
Introduction to japanese tokenizerFangda Wang
 
Gentle Introduction to Scala
Gentle Introduction to ScalaGentle Introduction to Scala
Gentle Introduction to ScalaFangda Wang
 
To pair or not to pair
To pair or not to pairTo pair or not to pair
To pair or not to pairFangda Wang
 
Elm at large (companies)
Elm at large (companies)Elm at large (companies)
Elm at large (companies)Fangda Wang
 
Data science tools of the trade
Data science tools of the tradeData science tools of the trade
Data science tools of the tradeFangda Wang
 

Mehr von Fangda Wang (11)

[WWCode] How aware are you of your deciding model?
[WWCode] How aware are you of your deciding model?[WWCode] How aware are you of your deciding model?
[WWCode] How aware are you of your deciding model?
 
Under the hood of architecture interviews at indeed
Under the hood of architecture interviews at indeedUnder the hood of architecture interviews at indeed
Under the hood of architecture interviews at indeed
 
How Indeed asks coding interview questions
How Indeed asks coding interview questionsHow Indeed asks coding interview questions
How Indeed asks coding interview questions
 
Types are eating the world
Types are eating the worldTypes are eating the world
Types are eating the world
 
From ic to tech lead
From ic to tech leadFrom ic to tech lead
From ic to tech lead
 
Introduction to japanese tokenizer
Introduction to japanese tokenizerIntroduction to japanese tokenizer
Introduction to japanese tokenizer
 
Gentle Introduction to Scala
Gentle Introduction to ScalaGentle Introduction to Scala
Gentle Introduction to Scala
 
To pair or not to pair
To pair or not to pairTo pair or not to pair
To pair or not to pair
 
Balanced Team
Balanced TeamBalanced Team
Balanced Team
 
Elm at large (companies)
Elm at large (companies)Elm at large (companies)
Elm at large (companies)
 
Data science tools of the trade
Data science tools of the tradeData science tools of the trade
Data science tools of the trade
 

Kürzlich hochgeladen

Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 

Kürzlich hochgeladen (20)

Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 

Functional programming and Elm

  • 3. Originated from lambda calculus developed in the 1930s by Alonzo Church What is Functional Programming? Programming with mathematical functions* *It doesn’t mean you need to know math
  • 4. • Do this, then do that • Any effect (Unsafe) • Commands (statements) • Control Flow • Name of a location Imperative • No notion of sequence • Limited effect (Safe) • Expressions • Data Flow • Name of a value vs. Functional
  • 5. f : a à World à (World, b) If there are no side-effects, how can we change the state of the world? f... takes in the state of the world and returns a new world, thus remaining pure No Side-effects update : Msg à Model à ( Model, Cmd Msg ) https://channel9.msdn.com/Shows/Going+Deep/Erik-Meijer-Functional-Programming
  • 6. Functional-flavored • Lisp 1958 (Scheme, Clojure, Racket) • ML ”Lisp with types” => Ocaml (F#, Scala, Reason) • Erlang (Elixir) • Javascript, Java 8, Kotlin, Perl, Python, PHP, etc. Functional-first, Pure • Haskell (Elm)
  • 7. Nirvana “Haskell is useless” Simon Peyton Jones Honesty/Dishonesty Erik Meijer https://www.youtube.com/watch?v=iSmkqocn0oQ&t=22s https://www.youtube.com/watch?v=z0N1aZ6SnBk&t=533 https://www.infoq.com/presentations/Taming-Effect-Simon-Peyton-Jones
  • 9. Web Development Fatigue3 Javascript fatigue + CSS fatigue + Framework/Npm fatigue = Web Development Fatigue
  • 10. What if I told you Front-end can be done without Javascript, HTML, CSS?
  • 11. Elm
  • 12. ● Pure Functional Language ● Compiles to Javascript ● Statically typed + inferred ● Support Immutability and Currying ● Virtual DOM What is Elm?
  • 13. ● Designed by Evan Czaplicki ● April 2012: Version 0.1 ● August 2018: Latest version 0.19 ● Stable (21 months since 0.18) ● Community in elmlang.slack.com History
  • 14. ● No loops (“i = i + 1” doesn’t compile) ● No “null” and no “undefined” ● No “return”, everything is an expression ● “if” always need “else” ● No “this”, no callbacks, no closures, no hoisting ● No automatic type conversion ● JSON decoder/encoder instead of stringify/parse Differences with Javascript
  • 15. Javascript Elm npm / yarn Built in React / Angular / Vue Flux / Redux / MobX Built in Built in Immutable.js Typescript / Flow Built in Built in
  • 16. Without HTML, CSS: elm-ui row [ padding 10, spacing 7 ] [ el [] none , el [] none , el [] none ] spacing : Distance between children padding : Parent Padding
  • 17. [ centerX , centerY ] .parent { position: relative; } .child { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } CSS elm-ui No more CSS tricks
  • 19. Nice thing #1 Helpful, friendly errors
  • 20. Nice thing #2 No runtime exceptions
  • 24. Nice thing #6 Type inference
  • 26. Nice thing #8 Demystify FP concepts Functors Monads Category Theory Algebraic Data Type
  • 27. The Elm Architecture is a simple pattern for architecting webapps. It is made of thee parts Nice thing #9 The Elm Architecture (TEA) Model the state of your application View a way to view your state as HTML Update a way to update your state
  • 28. 28 Cartoon cute unicorns vectors design by loutpany from https://freedesignfile.com
  • 29. Safe AreaUnsafe Area Elm Runtime DOM MsgModel Model Model Html Model New! Effects http requests, ports Cmd EventEvent! New! New! Cmd DOM Html EventEvent! update view
  • 31. [1,2] + [3,4] = ? Error [1,2,3,4] [4,6] “1,23,4” A B C D
  • 32. "1,23,4" Javascript Elm -- TYPE MISMATCH --------------------- I cannot do addition with lists: [1,2] + [3,4] ^^^^^ The left side of (+) is a list of type: List number But (+) only works with Int and Float values. Hint: Switch to the (++) operator to append lists! [1,2] + [3,4] = ?
  • 33. What can go wrong with automatic type conversion? https://itnext.io/things-that-can-go-wrong-without-a-strictly-typed-language-d91d418a53a1
  • 34.
  • 35. “If you want user input to be automatically typecast as a number, you can add the number modifier to your v- model managed inputs” <input type="number" v-model="product.quantity"> <input type="number" v-model.number="product.quantity">
  • 36. totalProducts() { return this.products.reduce((sum, product) => { return sum + product.quantity }, 0) } totalProducts() { return this.products.reduce((sum, product) => { if (typeof product.quantity === "number") { return sum + product.quantity; } else { return sum; } }, 0) }
  • 37. <button @click="product.quantity += 1"> <button @click="product.quantity = Number(product.quantity) + 1">
  • 38. Now it works but...
  • 39. type alias Product = { id : Int , quantity : Int , name : String } changeQuantity : Product -> String -> Product changeQuantity product newQuantity = { product | quantity = Maybe.withDefault product.quantity (String.toInt newQuantity) } “If the user typed a valid number, replace the old number with the new one, otherwise keep the old number”
  • 40. Typos <input v-model.number="product.quanity"> t Elm Fail silently Input fields are empty but buttons work. -- TYPE MISMATCH -------------------- The 2nd argument to `map` is not what I expect: 84| products ^^^^^^^^ This `products` value is a: List Product But `map` needs the 2nd argument to be: List { a | id : Int, name : String, quanity : Int, quantity : Int } Hint: Seems like a record field typo. Maybe quanity should be quantity? Vue
  • 41. C de
  • 42. module Main exposing (main) import Html exposing (..) import Html.Attributes exposing (..) main = div [] [ button [id "counter"] [ text "+1" ] , div [] [ text <| String.fromInt 0 ] , button [] [ text ”-1" ] ] <div id="counter"> <button>+1</button> <div>0</div> <button>-1</button> </div>
  • 43. -- MODEL type alias Model = { count : Int } init : Model init = { count = 0 }
  • 44. -- UPDATE type Msg = Increment | Decrement update : Msg -> Model -> Model update msg model = case msg of Increment -> { model | count = model.count + 1 } Decrement -> { model | count = model.count - 1 }
  • 45. -- VIEW view : Model -> Html Msg view model = layout [] <| column [] [ button [] { onPress = Just Increment , label = text "+1" } , el [] <| text (String.fromInt model.count) , button [] { onPress = Just Decrement , label = text "-1" } ]
  • 46. main : Program () Model Msg main = Browser.sandbox { init = init , view = view , update = update }
  • 52. ● The ideas of Functional Programming are becoming mainstream (for a reason) ● Learning Elm will make you a better [Javascript, React, Angular, Vue, etc.] developer ● Writing pure code is an enjoyable experience that make front-end development fun again!