SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
CHEAT-SHEET
Folding
#1
∢
/ 
π’‚πŸŽ ∢
/ 
π’‚πŸ ∢
/ 
π’‚πŸ ∢
/ 
π’‚πŸ‘
𝒇
/ 
π’‚πŸŽ 𝒇
/ 
π’‚πŸ 𝒇
/ 
π’‚πŸ 𝒇
/ 
π’‚πŸ‘ 𝒆
@philip_schwarz
slides by https://fpilluminated.com/
𝐝𝐚𝐭𝐚 𝑡𝒂𝒕 = 𝒁𝒆𝒓𝒐 | 𝑺𝒖𝒄𝒄 𝑡𝒂𝒕 𝐝𝐚𝐭𝐚 π‘³π’Šπ’”π’• Ξ± = π‘΅π’Šπ’ | π‘ͺ𝒐𝒏𝒔 Ξ± (π‘³π’Šπ’”π’• Ξ±)
𝑓 :: 𝑡𝒂𝒕 β†’ 𝛼
𝑓 𝒁𝒆𝒓𝒐 = 𝑐
𝑓 𝑺𝒖𝒄𝒄 𝑛 = β„Ž 𝑓 𝑛
π‘“π‘œπ‘™π‘‘π‘› ∷ 𝛼 β†’ 𝛼 β†’ 𝛼 β†’ 𝑡𝒂𝒕 β†’ 𝛼
π‘“π‘œπ‘™π‘‘π‘› β„Ž 𝑐 𝒁𝒆𝒓𝒐 = 𝑐
π‘“π‘œπ‘™π‘‘π‘› β„Ž 𝑐 𝑺𝒖𝒄𝒄 𝑛 = β„Ž π‘“π‘œπ‘™π‘‘π‘› β„Ž 𝑐 𝑛
π‘š + 𝑛 = π‘“π‘œπ‘™π‘‘π‘› 𝑺𝒖𝒄𝒄 π‘š 𝑛
π‘š Γ— 𝑛 = π‘“π‘œπ‘™π‘‘π‘› πœ†π‘₯. π‘₯ + π‘š 𝒁𝒆𝒓𝒐 𝑛
π‘š ↑ 𝑛 = π‘“π‘œπ‘™π‘‘π‘› πœ†π‘₯. π‘₯ Γ— π‘š 𝑺𝒖𝒄𝒄 𝒁𝒆𝒓𝒐 𝑛
+ ∷ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕
π‘š + 𝒁𝒆𝒓𝒐 = π‘š
π‘š + 𝑺𝒖𝒄𝒄 𝑛 = 𝑺𝒖𝒄𝒄 π‘š + 𝑛
(Γ—) ∷ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕
π‘š Γ— 𝒁𝒆𝒓𝒐 = 𝒁𝒆𝒓𝒐
π‘š Γ— 𝑺𝒖𝒄𝒄 𝑛 = π‘š Γ— 𝑛 + π‘š
(↑) ∷ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕
π‘š ↑ 𝒁𝒆𝒓𝒐 = 𝑺𝒖𝒄𝒄 𝒁𝒆𝒓𝒐
π‘š ↑ 𝑺𝒖𝒄𝒄 𝑛 = π‘š ↑ 𝑛 Γ— π‘š
π‘“π‘œπ‘™π‘‘π‘Ÿ ∷ 𝛼 β†’ 𝛽 β†’ 𝛽 β†’ 𝛽 β†’ 𝛼 β†’ 𝛽
π‘“π‘œπ‘™π‘‘π‘Ÿ 𝑓 𝑏 π‘΅π’Šπ’ = 𝑏
π‘“π‘œπ‘™π‘‘π‘Ÿ 𝑓 𝑏 (π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠) = 𝑓 π‘₯ π‘“π‘œπ‘™π‘‘π‘Ÿ 𝑓 𝑏 π‘₯𝑠
𝑓 :: π‘³π’Šπ’”π’• 𝛼 β†’ 𝛽
𝑓 π‘΅π’Šπ’ = 𝑐
𝑓 π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠 = β„Ž π‘₯ (𝑓 π‘₯𝑠)
π‘ π‘’π‘š ∷ π‘³π’Šπ’”π’• 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕
π‘ π‘’π‘š π‘΅π’Šπ’ = 𝒁𝒆𝒓𝒐
π‘ π‘’π‘š π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠 = π‘₯ + (π‘ π‘’π‘š π‘₯𝑠)
π‘Žπ‘π‘π‘’π‘›π‘‘ ∷ π‘³π’Šπ’”π’• 𝛼 β†’ π‘³π’Šπ’”π’• 𝛼 β†’ π‘³π’Šπ’”π’• 𝛼
π‘Žπ‘π‘π‘’π‘›π‘‘ π‘΅π’Šπ’ 𝑦𝑠 = 𝑦𝑠
π‘Žπ‘π‘π‘’π‘›π‘‘ π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠 𝑦𝑠 = π‘ͺ𝒐𝒏𝒔 π‘₯ (π‘Žπ‘π‘π‘’π‘›π‘‘ π‘₯𝑠 𝑦𝑠)
π‘™π‘’π‘›π‘”π‘‘β„Ž ∷ π‘³π’Šπ’”π’• 𝛼 β†’ 𝑡𝒂𝒕
π‘™π‘’π‘›π‘”π‘‘β„Ž π‘΅π’Šπ’ = 𝒁𝒆𝒓𝒐
π‘™π‘’π‘›π‘”π‘‘β„Ž π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠 = 𝑺𝒖𝒄𝒄 𝒁𝒆𝒓𝒐 + (π‘™π‘’π‘›π‘”π‘‘β„Ž π‘₯𝑠)
π‘ π‘’π‘š π‘₯𝑠 = π‘“π‘œπ‘™π‘‘π‘Ÿ + 𝒁𝒆𝒓𝒐 π‘₯𝑠
π‘™π‘’π‘›π‘”π‘‘β„Ž π‘₯𝑠 = π‘“π‘œπ‘™π‘‘π‘Ÿ πœ†π‘₯. πœ†π‘›. 𝑛 + 𝑺𝒖𝒄𝒄 𝒁𝒆𝒓𝒐 𝒁𝒆𝒓𝒐 π‘₯𝑠
π‘Žπ‘π‘π‘’π‘›π‘‘ π‘₯𝑠 𝑦𝑠 = π‘“π‘œπ‘™π‘‘π‘Ÿ π‘ͺ𝒐𝒏𝒔 𝑦𝑠 π‘₯𝑠
Common pattern for many recursive functions over 𝑡𝒂𝒕 : Common pattern for many recursive functions over π‘³π’Šπ’”π’•:
𝑐 :: 𝛼
β„Ž :: 𝛼 β†’ 𝛼
𝑐 :: 𝛽
β„Ž :: 𝛼 β†’ 𝛽
Three examples of such functions: Three examples of such functions:
The common pattern can be captured in a function: The common pattern can be captured in a function:
The three sample functions implemented using π‘“π‘œπ‘™π‘‘π‘›: The three sample functions implemented using π‘“π‘œπ‘™π‘‘π‘Ÿ:
https://fpilluminated.com/
inspired
by

Weitere Γ€hnliche Inhalte

Γ„hnlich wie Folding Cheat Sheet #1 - first in a series

Γ„hnlich wie Folding Cheat Sheet #1 - first in a series (20)

Folding Cheat Sheet #2 - second in a series
Folding Cheat Sheet #2 - second in a seriesFolding Cheat Sheet #2 - second in a series
Folding Cheat Sheet #2 - second in a series
Β 
Folding Cheat Sheet #2 - second in a series
Folding Cheat Sheet #2 - second in a seriesFolding Cheat Sheet #2 - second in a series
Folding Cheat Sheet #2 - second in a series
Β 
Sets
SetsSets
Sets
Β 
Photosynthesis
PhotosynthesisPhotosynthesis
Photosynthesis
Β 
Instrumental Variables
Instrumental VariablesInstrumental Variables
Instrumental Variables
Β 
SUEC 高中 Adv Maths (Irrational Part 3)
SUEC 高中 Adv Maths (Irrational Part 3)SUEC 高中 Adv Maths (Irrational Part 3)
SUEC 高中 Adv Maths (Irrational Part 3)
Β 
Review of generative adversarial nets
Review of generative adversarial netsReview of generative adversarial nets
Review of generative adversarial nets
Β 
07.mdsd_modelado_termicos_liquidos
07.mdsd_modelado_termicos_liquidos07.mdsd_modelado_termicos_liquidos
07.mdsd_modelado_termicos_liquidos
Β 
On ranges and null spaces of a special type of operator named 𝝀 βˆ’ π’‹π’†π’„π’•π’Šπ’π’. – ...
On ranges and null spaces of a special type of operator named 𝝀 βˆ’ π’‹π’†π’„π’•π’Šπ’π’. – ...On ranges and null spaces of a special type of operator named 𝝀 βˆ’ π’‹π’†π’„π’•π’Šπ’π’. – ...
On ranges and null spaces of a special type of operator named 𝝀 βˆ’ π’‹π’†π’„π’•π’Šπ’π’. – ...
Β 
Enzymes
EnzymesEnzymes
Enzymes
Β 
SUEC 高中 Adv Maths (Biquadratic Equation, Method of Changing the Variable, Rec...
SUEC 高中 Adv Maths (Biquadratic Equation, Method of Changing the Variable, Rec...SUEC 高中 Adv Maths (Biquadratic Equation, Method of Changing the Variable, Rec...
SUEC 高中 Adv Maths (Biquadratic Equation, Method of Changing the Variable, Rec...
Β 
Ch 5 integration
Ch 5 integration  Ch 5 integration
Ch 5 integration
Β 
Integration
IntegrationIntegration
Integration
Β 
SUEC 高中 Adv Maths (Quadratic Equation in One Variable)
SUEC 高中 Adv Maths (Quadratic Equation in One Variable)SUEC 高中 Adv Maths (Quadratic Equation in One Variable)
SUEC 高中 Adv Maths (Quadratic Equation in One Variable)
Β 
Carbohydrate Metabolism
Carbohydrate MetabolismCarbohydrate Metabolism
Carbohydrate Metabolism
Β 
Blow up in a degenerate keller--segel system(Eng.)
Blow up in a degenerate keller--segel system(Eng.)Blow up in a degenerate keller--segel system(Eng.)
Blow up in a degenerate keller--segel system(Eng.)
Β 
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 8 Rombel 3
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 8 Rombel 32018 Geometri Transformasi Perkalian 5 Isometri Kelompok 8 Rombel 3
2018 Geometri Transformasi Perkalian 5 Isometri Kelompok 8 Rombel 3
Β 
05.mdsd_modelado_mecanico_electrico
05.mdsd_modelado_mecanico_electrico05.mdsd_modelado_mecanico_electrico
05.mdsd_modelado_mecanico_electrico
Β 
Teoria NumΓ©rica (Palestra 01)
Teoria NumΓ©rica (Palestra 01)Teoria NumΓ©rica (Palestra 01)
Teoria NumΓ©rica (Palestra 01)
Β 
Selection on Observables
Selection on ObservablesSelection on Observables
Selection on Observables
Β 

Mehr von Philip Schwarz

N-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets CatsN-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets Cats
Philip Schwarz
Β 

Mehr von Philip Schwarz (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Β 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
Β 
Scala Left Fold Parallelisation - Three Approaches
Scala Left Fold Parallelisation- Three ApproachesScala Left Fold Parallelisation- Three Approaches
Scala Left Fold Parallelisation - Three Approaches
Β 
Tagless Final Encoding - Algebras and Interpreters and also Programs
Tagless Final Encoding - Algebras and Interpreters and also ProgramsTagless Final Encoding - Algebras and Interpreters and also Programs
Tagless Final Encoding - Algebras and Interpreters and also Programs
Β 
Fusing Transformations of Strict Scala Collections with Views
Fusing Transformations of Strict Scala Collections with ViewsFusing Transformations of Strict Scala Collections with Views
Fusing Transformations of Strict Scala Collections with Views
Β 
A sighting of traverse_ function in Practical FP in Scala
A sighting of traverse_ function in Practical FP in ScalaA sighting of traverse_ function in Practical FP in Scala
A sighting of traverse_ function in Practical FP in Scala
Β 
A sighting of traverseFilter and foldMap in Practical FP in Scala
A sighting of traverseFilter and foldMap in Practical FP in ScalaA sighting of traverseFilter and foldMap in Practical FP in Scala
A sighting of traverseFilter and foldMap in Practical FP in Scala
Β 
A sighting of sequence function in Practical FP in Scala
A sighting of sequence function in Practical FP in ScalaA sighting of sequence function in Practical FP in Scala
A sighting of sequence function in Practical FP in Scala
Β 
N-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets CatsN-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets Cats
Β 
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...Kleisli composition, flatMap, join, map, unit - implementation and interrelat...
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...
Β 
The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...
Β 
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Nat, List and Option Monoids -from scratch -Combining and Folding -an exampleNat, List and Option Monoids -from scratch -Combining and Folding -an example
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Β 
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Nat, List and Option Monoids -from scratch -Combining and Folding -an exampleNat, List and Option Monoids -from scratch -Combining and Folding -an example
Nat, List and Option Monoids - from scratch - Combining and Folding - an example
Β 
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
Β 
Sum and Product Types - The Fruit Salad & Fruit Snack Example - From F# to Ha...
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...
Sum and Product Types - The Fruit Salad & Fruit Snack Example - From F# to Ha...
Β 
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
Β 
Jordan Peterson - The pursuit of meaning and related ethical axioms
Jordan Peterson - The pursuit of meaning and related ethical axiomsJordan Peterson - The pursuit of meaning and related ethical axioms
Jordan Peterson - The pursuit of meaning and related ethical axioms
Β 
Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...
Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...
Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...
Β 
Defining filter using (a) recursion (b) folding with S, B and I combinators (...
Defining filter using (a) recursion (b) folding with S, B and I combinators (...Defining filter using (a) recursion (b) folding with S, B and I combinators (...
Defining filter using (a) recursion (b) folding with S, B and I combinators (...
Β 
The Sieve of Eratosthenes - Part 1 - with minor corrections
The Sieve of Eratosthenes - Part 1 - with minor correctionsThe Sieve of Eratosthenes - Part 1 - with minor corrections
The Sieve of Eratosthenes - Part 1 - with minor corrections
Β 

KΓΌrzlich hochgeladen

KΓΌrzlich hochgeladen (20)

The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
Β 
Abortion Pill Prices Turfloop ](+27832195400*)[ πŸ₯ Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ πŸ₯ Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ πŸ₯ Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ πŸ₯ Women's Abortion Clinic in ...
Β 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
Β 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
Β 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
Β 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Β 
Abortion Clinic In Pretoria ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Pretor...
Β 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Β 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Β 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
Β 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Β 
Abortion Clinic In Springs ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Springs...
Β 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
Β 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
Β 
Abortion Clinic In Johannesburg ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ πŸ₯ Safe Abortion Pills in Jo...
Β 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
Β 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Β 
Abortion Pill Prices Jane Furse ](+27832195400*)[ πŸ₯ Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ πŸ₯ Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ πŸ₯ Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ πŸ₯ Women's Abortion Clinic i...
Β 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
Β 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
Β 

Folding Cheat Sheet #1 - first in a series

  • 1. CHEAT-SHEET Folding #1 ∢ / π’‚πŸŽ ∢ / π’‚πŸ ∢ / π’‚πŸ ∢ / π’‚πŸ‘ 𝒇 / π’‚πŸŽ 𝒇 / π’‚πŸ 𝒇 / π’‚πŸ 𝒇 / π’‚πŸ‘ 𝒆 @philip_schwarz slides by https://fpilluminated.com/
  • 2. 𝐝𝐚𝐭𝐚 𝑡𝒂𝒕 = 𝒁𝒆𝒓𝒐 | 𝑺𝒖𝒄𝒄 𝑡𝒂𝒕 𝐝𝐚𝐭𝐚 π‘³π’Šπ’”π’• Ξ± = π‘΅π’Šπ’ | π‘ͺ𝒐𝒏𝒔 Ξ± (π‘³π’Šπ’”π’• Ξ±) 𝑓 :: 𝑡𝒂𝒕 β†’ 𝛼 𝑓 𝒁𝒆𝒓𝒐 = 𝑐 𝑓 𝑺𝒖𝒄𝒄 𝑛 = β„Ž 𝑓 𝑛 π‘“π‘œπ‘™π‘‘π‘› ∷ 𝛼 β†’ 𝛼 β†’ 𝛼 β†’ 𝑡𝒂𝒕 β†’ 𝛼 π‘“π‘œπ‘™π‘‘π‘› β„Ž 𝑐 𝒁𝒆𝒓𝒐 = 𝑐 π‘“π‘œπ‘™π‘‘π‘› β„Ž 𝑐 𝑺𝒖𝒄𝒄 𝑛 = β„Ž π‘“π‘œπ‘™π‘‘π‘› β„Ž 𝑐 𝑛 π‘š + 𝑛 = π‘“π‘œπ‘™π‘‘π‘› 𝑺𝒖𝒄𝒄 π‘š 𝑛 π‘š Γ— 𝑛 = π‘“π‘œπ‘™π‘‘π‘› πœ†π‘₯. π‘₯ + π‘š 𝒁𝒆𝒓𝒐 𝑛 π‘š ↑ 𝑛 = π‘“π‘œπ‘™π‘‘π‘› πœ†π‘₯. π‘₯ Γ— π‘š 𝑺𝒖𝒄𝒄 𝒁𝒆𝒓𝒐 𝑛 + ∷ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 π‘š + 𝒁𝒆𝒓𝒐 = π‘š π‘š + 𝑺𝒖𝒄𝒄 𝑛 = 𝑺𝒖𝒄𝒄 π‘š + 𝑛 (Γ—) ∷ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 π‘š Γ— 𝒁𝒆𝒓𝒐 = 𝒁𝒆𝒓𝒐 π‘š Γ— 𝑺𝒖𝒄𝒄 𝑛 = π‘š Γ— 𝑛 + π‘š (↑) ∷ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 π‘š ↑ 𝒁𝒆𝒓𝒐 = 𝑺𝒖𝒄𝒄 𝒁𝒆𝒓𝒐 π‘š ↑ 𝑺𝒖𝒄𝒄 𝑛 = π‘š ↑ 𝑛 Γ— π‘š π‘“π‘œπ‘™π‘‘π‘Ÿ ∷ 𝛼 β†’ 𝛽 β†’ 𝛽 β†’ 𝛽 β†’ 𝛼 β†’ 𝛽 π‘“π‘œπ‘™π‘‘π‘Ÿ 𝑓 𝑏 π‘΅π’Šπ’ = 𝑏 π‘“π‘œπ‘™π‘‘π‘Ÿ 𝑓 𝑏 (π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠) = 𝑓 π‘₯ π‘“π‘œπ‘™π‘‘π‘Ÿ 𝑓 𝑏 π‘₯𝑠 𝑓 :: π‘³π’Šπ’”π’• 𝛼 β†’ 𝛽 𝑓 π‘΅π’Šπ’ = 𝑐 𝑓 π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠 = β„Ž π‘₯ (𝑓 π‘₯𝑠) π‘ π‘’π‘š ∷ π‘³π’Šπ’”π’• 𝑡𝒂𝒕 β†’ 𝑡𝒂𝒕 π‘ π‘’π‘š π‘΅π’Šπ’ = 𝒁𝒆𝒓𝒐 π‘ π‘’π‘š π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠 = π‘₯ + (π‘ π‘’π‘š π‘₯𝑠) π‘Žπ‘π‘π‘’π‘›π‘‘ ∷ π‘³π’Šπ’”π’• 𝛼 β†’ π‘³π’Šπ’”π’• 𝛼 β†’ π‘³π’Šπ’”π’• 𝛼 π‘Žπ‘π‘π‘’π‘›π‘‘ π‘΅π’Šπ’ 𝑦𝑠 = 𝑦𝑠 π‘Žπ‘π‘π‘’π‘›π‘‘ π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠 𝑦𝑠 = π‘ͺ𝒐𝒏𝒔 π‘₯ (π‘Žπ‘π‘π‘’π‘›π‘‘ π‘₯𝑠 𝑦𝑠) π‘™π‘’π‘›π‘”π‘‘β„Ž ∷ π‘³π’Šπ’”π’• 𝛼 β†’ 𝑡𝒂𝒕 π‘™π‘’π‘›π‘”π‘‘β„Ž π‘΅π’Šπ’ = 𝒁𝒆𝒓𝒐 π‘™π‘’π‘›π‘”π‘‘β„Ž π‘ͺ𝒐𝒏𝒔 π‘₯ π‘₯𝑠 = 𝑺𝒖𝒄𝒄 𝒁𝒆𝒓𝒐 + (π‘™π‘’π‘›π‘”π‘‘β„Ž π‘₯𝑠) π‘ π‘’π‘š π‘₯𝑠 = π‘“π‘œπ‘™π‘‘π‘Ÿ + 𝒁𝒆𝒓𝒐 π‘₯𝑠 π‘™π‘’π‘›π‘”π‘‘β„Ž π‘₯𝑠 = π‘“π‘œπ‘™π‘‘π‘Ÿ πœ†π‘₯. πœ†π‘›. 𝑛 + 𝑺𝒖𝒄𝒄 𝒁𝒆𝒓𝒐 𝒁𝒆𝒓𝒐 π‘₯𝑠 π‘Žπ‘π‘π‘’π‘›π‘‘ π‘₯𝑠 𝑦𝑠 = π‘“π‘œπ‘™π‘‘π‘Ÿ π‘ͺ𝒐𝒏𝒔 𝑦𝑠 π‘₯𝑠 Common pattern for many recursive functions over 𝑡𝒂𝒕 : Common pattern for many recursive functions over π‘³π’Šπ’”π’•: 𝑐 :: 𝛼 β„Ž :: 𝛼 β†’ 𝛼 𝑐 :: 𝛽 β„Ž :: 𝛼 β†’ 𝛽 Three examples of such functions: Three examples of such functions: The common pattern can be captured in a function: The common pattern can be captured in a function: The three sample functions implemented using π‘“π‘œπ‘™π‘‘π‘›: The three sample functions implemented using π‘“π‘œπ‘™π‘‘π‘Ÿ: