SlideShare a Scribd company logo
1 of 3
Download to read offline
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

More Related Content

Similar to Folding Cheat Sheet #1 - first 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 seriesPhilip Schwarz
Β 
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 seriesPhilip Schwarz
Β 
SUEC 高中 Adv Maths (Irrational Part 3)
SUEC 高中 Adv Maths (Irrational Part 3)SUEC 高中 Adv Maths (Irrational Part 3)
SUEC 高中 Adv Maths (Irrational Part 3)tungwc
Β 
Review of generative adversarial nets
Review of generative adversarial netsReview of generative adversarial nets
Review of generative adversarial netsSungminYou
Β 
07.mdsd_modelado_termicos_liquidos
07.mdsd_modelado_termicos_liquidos07.mdsd_modelado_termicos_liquidos
07.mdsd_modelado_termicos_liquidosHipΓ³lito Aguilar
Β 
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 𝝀 βˆ’ π’‹π’†π’„π’•π’Šπ’π’. – ...IJMER
Β 
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...tungwc
Β 
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)tungwc
Β 
Carbohydrate Metabolism
Carbohydrate MetabolismCarbohydrate Metabolism
Carbohydrate MetabolismVedantPatel100
Β 
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.)Takahiro Hashira
Β 
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 3Yosia Adi Setiawan
Β 
05.mdsd_modelado_mecanico_electrico
05.mdsd_modelado_mecanico_electrico05.mdsd_modelado_mecanico_electrico
05.mdsd_modelado_mecanico_electricoHipΓ³lito Aguilar
Β 
Teoria NumΓ©rica (Palestra 01)
Teoria NumΓ©rica (Palestra 01)Teoria NumΓ©rica (Palestra 01)
Teoria NumΓ©rica (Palestra 01)Eugenio Souza
Β 
Selection on Observables
Selection on ObservablesSelection on Observables
Selection on ObservablesMEASURE Evaluation
Β 

Similar to 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
Β 

More from Philip Schwarz

Scala Left Fold Parallelisation - Three Approaches
Scala Left Fold Parallelisation- Three ApproachesScala Left Fold Parallelisation- Three Approaches
Scala Left Fold Parallelisation - Three ApproachesPhilip Schwarz
Β 
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 ProgramsPhilip Schwarz
Β 
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 ViewsPhilip Schwarz
Β 
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 ScalaPhilip Schwarz
Β 
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 ScalaPhilip Schwarz
Β 
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 ScalaPhilip Schwarz
Β 
N-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets CatsN-Queens Combinatorial Puzzle meets Cats
N-Queens Combinatorial Puzzle meets CatsPhilip Schwarz
Β 
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...Philip Schwarz
Β 
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...Philip Schwarz
Β 
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 examplePhilip Schwarz
Β 
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 examplePhilip Schwarz
Β 
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...Philip Schwarz
Β 
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...Philip Schwarz
Β 
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...Philip Schwarz
Β 
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 axiomsPhilip Schwarz
Β 
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...Philip Schwarz
Β 
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 (...Philip Schwarz
Β 
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 correctionsPhilip Schwarz
Β 
The Sieve of Eratosthenes - Part 1
The Sieve of Eratosthenes - Part 1The Sieve of Eratosthenes - Part 1
The Sieve of Eratosthenes - Part 1Philip Schwarz
Β 
The Uniform Access Principle
The Uniform Access PrincipleThe Uniform Access Principle
The Uniform Access PrinciplePhilip Schwarz
Β 

More from Philip Schwarz (20)

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
Β 
The Sieve of Eratosthenes - Part 1
The Sieve of Eratosthenes - Part 1The Sieve of Eratosthenes - Part 1
The Sieve of Eratosthenes - Part 1
Β 
The Uniform Access Principle
The Uniform Access PrincipleThe Uniform Access Principle
The Uniform Access Principle
Β 

Recently uploaded

Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
Β 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
Β 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
Β 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
Β 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
Β 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
Β 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
Β 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
Β 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
Β 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
Β 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
Β 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
Β 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
Β 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
Β 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
Β 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
Β 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
Β 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
Β 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
Β 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
Β 

Recently uploaded (20)

Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
Β 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
Β 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
Β 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Β 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
Β 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
Β 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
Β 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
Β 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
Β 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Β 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
Β 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
Β 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
Β 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
Β 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Β 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
Β 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Β 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
Β 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Β 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.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 π‘“π‘œπ‘™π‘‘π‘Ÿ: