SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
CHEAT-SHEET
Folding
#3
∶
/ 
𝒂𝟎 ∶
/ 
𝒂𝟏 ∶
/ 
𝒂𝟐 ∶
/ 
𝒂𝟑
𝒇
/ 
𝒂𝟎 𝒇
/ 
𝒂𝟏 𝒇
/ 
𝒂𝟐 𝒇
/ 
𝒂𝟑 𝒆
@philip_schwarz
slides by https://fpilluminated.com/
The universal property of 𝒇𝒐𝒍𝒅
...
For finite lists, the universal property of 𝒇𝒐𝒍𝒅 can be stated as the following equivalence between two definitions for a function 𝒈 that
processes lists:
𝒈 = 𝒗 ⟺ 𝒈 = 𝒇𝒐𝒍𝒅 𝒇 𝒗
𝒈 𝑥 ∶ 𝑥𝑠 = 𝒇 𝑥 𝒈 𝑥𝑠
In the right-to-left direction, substituting 𝒈 = 𝒇𝒐𝒍𝒅 𝒇 𝒗 into the two equations for 𝒈 gives the recursive definition for 𝒇𝒐𝒍𝒅.
Conversely, in the left-to-right direction the two equations for g are precisely the assumptions required to show that 𝒈 = 𝒇𝒐𝒍𝒅 𝒇 𝒗 using a
simple proof by induction on finite lists…
Taken as a whole, the universal property states that for finite lists the function 𝒇𝒐𝒍𝒅 𝒇 𝒗 is not just a solution to its defining equations, but
in fact the unique solution….
The universal property of 𝒇𝒐𝒍𝒅 can be generalised to handle partial and infinite lists…
Graham Hutton
@haskelhutt
𝑓𝑜𝑙𝑑 :: 𝛼 → 𝛽 → 𝛽 → 𝛽 → 𝛼 → 𝛽
𝑓𝑜𝑙𝑑 𝑓 𝑣 = 𝑣
𝑓𝑜𝑙𝑑 𝑓 𝑣 𝑥 ∶ 𝑥𝑠 = 𝑓 𝑥 𝑓𝑜𝑙𝑑 𝑓 𝑣 𝑥𝑠
𝑔 = 𝑣
𝑔 𝑥 ∶ 𝑥𝑠 = 𝑓 𝑥 𝑔 𝑥𝑠
𝑠𝑢𝑚 ∷ 𝐼𝑛𝑡 → 𝐼𝑛𝑡
𝑠𝑢𝑚 = 0
𝑠𝑢𝑚 𝑥 ∶ 𝑥𝑠 = 𝑥 + 𝑠𝑢𝑚 𝑥𝑠
𝑠𝑢𝑚 = 𝑓𝑜𝑙𝑑 + 0
⟺
𝑔 = 𝑓𝑜𝑙𝑑 𝑓 𝑣
⟺
𝑝𝑟𝑜𝑑𝑢𝑐𝑡 ∷ 𝐼𝑛𝑡 → 𝐼𝑛𝑡
𝑝𝑟𝑜𝑑𝑢𝑐𝑡 = 1
𝑝𝑟𝑜𝑑𝑢𝑐𝑡 𝑥 ∶ 𝑥𝑠 = 𝑥 × 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 𝑥𝑠
𝑝𝑟𝑜𝑑𝑢𝑐𝑡 = 𝑓𝑜𝑙𝑑 (×) 1
⟺
𝑙𝑒𝑛𝑔𝑡ℎ ∷ [α] → 𝐼𝑛𝑡
𝑙𝑒𝑛𝑔𝑡ℎ [ ] = 0
𝑙𝑒𝑛𝑔𝑡ℎ 𝑥 ∶ 𝑥𝑠 = 1 + 𝑙𝑒𝑛𝑔𝑡ℎ 𝑥𝑠
𝑙𝑒𝑛𝑔𝑡ℎ = 𝑓𝑜𝑙𝑑 (𝜆𝑥. 𝜆𝑛. 1 + 𝑛) 0
⟺
(⧺) ∷ [α] → [α] → [α]
⧺ 𝑦𝑠 = 𝑦𝑠
𝑥 ∶ 𝑥𝑠 ⧺ 𝑦𝑠 = 𝑥 ∶ (𝑥𝑠 ⧺ 𝑦𝑠)
(⧺ 𝑦𝑠) = 𝑓𝑜𝑙𝑑 ∶ 𝑦𝑠
⟺
concat ∷ [ α ] → [α]
concat =
concat 𝑥𝑠 ∶ 𝑥𝑠𝑠 = 𝑥𝑠 ⧺ 𝑐𝑜𝑛𝑐𝑎𝑡 𝑥𝑠𝑠
⟺ concat = 𝑓𝑜𝑙𝑑 (⧺) [ ]
The Triad of
𝑚𝑎𝑝, 𝑓𝑖𝑙𝑡𝑒𝑟 and 𝑓𝑜𝑙𝑑
𝑚𝑎𝑝
λ
The 𝑏𝑟𝑒𝑎𝑑, 𝑏𝑢𝑡𝑡𝑒𝑟, and 𝑗𝑎𝑚 of
Functional Programming
=
𝑔 = 𝑣
𝑔 𝑥 ∶ 𝑥𝑠 = 𝑓 𝑥 𝑔 𝑥𝑠
𝑚𝑎𝑝 ∷ 𝛼 → 𝛽 → 𝛼 → 𝛽
𝑚𝑎𝑝 𝑓 =
𝑚𝑎𝑝 𝑓 𝑥 ∶ 𝑥𝑠 = 𝑓 𝑥 ∶ 𝑚𝑎𝑝 𝑓 𝑥𝑠
𝑚𝑎𝑝 𝑓 = 𝑓𝑜𝑙𝑑𝑟 𝜆𝑥. 𝜆𝑥𝑠. 𝑓 𝑥 ∶ 𝑥𝑠 [ ]
⟺
𝑓𝑖𝑙𝑡𝑒𝑟 ∷ (𝛼 → 𝐵𝑜𝑜𝑙) → 𝛼 → 𝑎
𝑓𝑖𝑙𝑡𝑒𝑟 p =
𝑓𝑖𝑙𝑡𝑒𝑟 p 𝑥 ∶ 𝑥𝑠 = 𝐢𝐟 𝑝 𝑥
𝐭𝐡𝐞𝐧 𝑥 ∶ 𝑓𝑖𝑙𝑡𝑒𝑟 p 𝑥𝑠
𝐞𝐥𝐬𝐞 𝑓𝑖𝑙𝑡𝑒𝑟 p 𝑥𝑠
𝑓𝑖𝑙𝑡𝑒𝑟 p = 𝑓𝑜𝑙𝑑𝑟 (𝜆𝑥. 𝜆𝑥𝑠. 𝐢𝐟 𝑝 𝑥 𝐭𝐡𝐞𝐧 𝑥 ∶ 𝑥𝑠 𝐞𝐥𝐬𝐞 𝑥𝑠) [ ]
⟺
𝑔 = 𝑓𝑜𝑙𝑑𝑟 𝑓 𝑣
⟺
𝑚𝑎𝑝
λ
𝑓𝑜𝑙𝑑
=
https://fpilluminated.com/
inspired
by

Contenu connexe

Similaire à Folding Cheat Sheet #3 - third in a series

Application of Convolution Theorem
Application of Convolution TheoremApplication of Convolution Theorem
Application of Convolution Theoremijtsrd
 
Laplace Transform and its applications
Laplace Transform and its applicationsLaplace Transform and its applications
Laplace Transform and its applicationsDeepRaval7
 
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptxDomain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptxNeomyAngelaLeono1
 
Taller grupal parcial ii nrc 3246 sebastian fueltala_kevin sánchez
Taller grupal parcial ii nrc 3246  sebastian fueltala_kevin sánchezTaller grupal parcial ii nrc 3246  sebastian fueltala_kevin sánchez
Taller grupal parcial ii nrc 3246 sebastian fueltala_kevin sánchezkevinct2001
 
C222529
C222529C222529
C222529irjes
 
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix MappingDual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mappinginventionjournals
 
Matrix Transformations on Some Difference Sequence Spaces
Matrix Transformations on Some Difference Sequence SpacesMatrix Transformations on Some Difference Sequence Spaces
Matrix Transformations on Some Difference Sequence SpacesIOSR Journals
 
Integrales definidas y método de integración por partes
Integrales definidas y método de integración por partesIntegrales definidas y método de integración por partes
Integrales definidas y método de integración por partescrysmari mujica
 
A Probabilistic Algorithm for Computation of Polynomial Greatest Common with ...
A Probabilistic Algorithm for Computation of Polynomial Greatest Common with ...A Probabilistic Algorithm for Computation of Polynomial Greatest Common with ...
A Probabilistic Algorithm for Computation of Polynomial Greatest Common with ...mathsjournal
 
Typesetting Mathematics with LaTeX - Day 2
Typesetting Mathematics with LaTeX - Day 2Typesetting Mathematics with LaTeX - Day 2
Typesetting Mathematics with LaTeX - Day 2Suddhasheel GHOSH, PhD
 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine LearningSEMINARGROOT
 
SPLIT PLOT DESIGN new.pptx
SPLIT PLOT DESIGN new.pptxSPLIT PLOT DESIGN new.pptx
SPLIT PLOT DESIGN new.pptxValeDiode
 
Semana 24 funciones iv álgebra uni ccesa007
Semana 24 funciones iv álgebra uni ccesa007Semana 24 funciones iv álgebra uni ccesa007
Semana 24 funciones iv álgebra uni ccesa007Demetrio Ccesa Rayme
 
Integral dalam Bahasa Inggris
Integral dalam Bahasa InggrisIntegral dalam Bahasa Inggris
Integral dalam Bahasa Inggrisimmochacha
 
Inverse Function.pptx
Inverse Function.pptxInverse Function.pptx
Inverse Function.pptxSerGeo5
 

Similaire à Folding Cheat Sheet #3 - third in a series (20)

Module 7 the antiderivative
Module 7  the antiderivativeModule 7  the antiderivative
Module 7 the antiderivative
 
Module 7 the antiderivative
Module 7  the antiderivativeModule 7  the antiderivative
Module 7 the antiderivative
 
Application of Convolution Theorem
Application of Convolution TheoremApplication of Convolution Theorem
Application of Convolution Theorem
 
PRODUCT RULES
PRODUCT RULESPRODUCT RULES
PRODUCT RULES
 
Laplace Transform and its applications
Laplace Transform and its applicationsLaplace Transform and its applications
Laplace Transform and its applications
 
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptxDomain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
Domain-Range-Intercepts-Zeros-and-Asymptotes-of-Rational-Function.pptx
 
Taller grupal parcial ii nrc 3246 sebastian fueltala_kevin sánchez
Taller grupal parcial ii nrc 3246  sebastian fueltala_kevin sánchezTaller grupal parcial ii nrc 3246  sebastian fueltala_kevin sánchez
Taller grupal parcial ii nrc 3246 sebastian fueltala_kevin sánchez
 
C222529
C222529C222529
C222529
 
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix MappingDual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
 
Matrix Transformations on Some Difference Sequence Spaces
Matrix Transformations on Some Difference Sequence SpacesMatrix Transformations on Some Difference Sequence Spaces
Matrix Transformations on Some Difference Sequence Spaces
 
Integrales definidas y método de integración por partes
Integrales definidas y método de integración por partesIntegrales definidas y método de integración por partes
Integrales definidas y método de integración por partes
 
A Probabilistic Algorithm for Computation of Polynomial Greatest Common with ...
A Probabilistic Algorithm for Computation of Polynomial Greatest Common with ...A Probabilistic Algorithm for Computation of Polynomial Greatest Common with ...
A Probabilistic Algorithm for Computation of Polynomial Greatest Common with ...
 
Typesetting Mathematics with LaTeX - Day 2
Typesetting Mathematics with LaTeX - Day 2Typesetting Mathematics with LaTeX - Day 2
Typesetting Mathematics with LaTeX - Day 2
 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine Learning
 
SPLIT PLOT DESIGN new.pptx
SPLIT PLOT DESIGN new.pptxSPLIT PLOT DESIGN new.pptx
SPLIT PLOT DESIGN new.pptx
 
Semana 24 funciones iv álgebra uni ccesa007
Semana 24 funciones iv álgebra uni ccesa007Semana 24 funciones iv álgebra uni ccesa007
Semana 24 funciones iv álgebra uni ccesa007
 
Integral dalam Bahasa Inggris
Integral dalam Bahasa InggrisIntegral dalam Bahasa Inggris
Integral dalam Bahasa Inggris
 
E0561719
E0561719E0561719
E0561719
 
Integral calculus
Integral calculusIntegral calculus
Integral calculus
 
Inverse Function.pptx
Inverse Function.pptxInverse Function.pptx
Inverse Function.pptx
 

Plus de Philip Schwarz

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 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
 
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
 

Plus de Philip Schwarz (20)

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
 
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
 
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
 

Dernier

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Dernier (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Folding Cheat Sheet #3 - third in a series

  • 1. CHEAT-SHEET Folding #3 ∶ / 𝒂𝟎 ∶ / 𝒂𝟏 ∶ / 𝒂𝟐 ∶ / 𝒂𝟑 𝒇 / 𝒂𝟎 𝒇 / 𝒂𝟏 𝒇 / 𝒂𝟐 𝒇 / 𝒂𝟑 𝒆 @philip_schwarz slides by https://fpilluminated.com/
  • 2. The universal property of 𝒇𝒐𝒍𝒅 ... For finite lists, the universal property of 𝒇𝒐𝒍𝒅 can be stated as the following equivalence between two definitions for a function 𝒈 that processes lists: 𝒈 = 𝒗 ⟺ 𝒈 = 𝒇𝒐𝒍𝒅 𝒇 𝒗 𝒈 𝑥 ∶ 𝑥𝑠 = 𝒇 𝑥 𝒈 𝑥𝑠 In the right-to-left direction, substituting 𝒈 = 𝒇𝒐𝒍𝒅 𝒇 𝒗 into the two equations for 𝒈 gives the recursive definition for 𝒇𝒐𝒍𝒅. Conversely, in the left-to-right direction the two equations for g are precisely the assumptions required to show that 𝒈 = 𝒇𝒐𝒍𝒅 𝒇 𝒗 using a simple proof by induction on finite lists… Taken as a whole, the universal property states that for finite lists the function 𝒇𝒐𝒍𝒅 𝒇 𝒗 is not just a solution to its defining equations, but in fact the unique solution…. The universal property of 𝒇𝒐𝒍𝒅 can be generalised to handle partial and infinite lists… Graham Hutton @haskelhutt 𝑓𝑜𝑙𝑑 :: 𝛼 → 𝛽 → 𝛽 → 𝛽 → 𝛼 → 𝛽 𝑓𝑜𝑙𝑑 𝑓 𝑣 = 𝑣 𝑓𝑜𝑙𝑑 𝑓 𝑣 𝑥 ∶ 𝑥𝑠 = 𝑓 𝑥 𝑓𝑜𝑙𝑑 𝑓 𝑣 𝑥𝑠
  • 3. 𝑔 = 𝑣 𝑔 𝑥 ∶ 𝑥𝑠 = 𝑓 𝑥 𝑔 𝑥𝑠 𝑠𝑢𝑚 ∷ 𝐼𝑛𝑡 → 𝐼𝑛𝑡 𝑠𝑢𝑚 = 0 𝑠𝑢𝑚 𝑥 ∶ 𝑥𝑠 = 𝑥 + 𝑠𝑢𝑚 𝑥𝑠 𝑠𝑢𝑚 = 𝑓𝑜𝑙𝑑 + 0 ⟺ 𝑔 = 𝑓𝑜𝑙𝑑 𝑓 𝑣 ⟺ 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 ∷ 𝐼𝑛𝑡 → 𝐼𝑛𝑡 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 = 1 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 𝑥 ∶ 𝑥𝑠 = 𝑥 × 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 𝑥𝑠 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 = 𝑓𝑜𝑙𝑑 (×) 1 ⟺ 𝑙𝑒𝑛𝑔𝑡ℎ ∷ [α] → 𝐼𝑛𝑡 𝑙𝑒𝑛𝑔𝑡ℎ [ ] = 0 𝑙𝑒𝑛𝑔𝑡ℎ 𝑥 ∶ 𝑥𝑠 = 1 + 𝑙𝑒𝑛𝑔𝑡ℎ 𝑥𝑠 𝑙𝑒𝑛𝑔𝑡ℎ = 𝑓𝑜𝑙𝑑 (𝜆𝑥. 𝜆𝑛. 1 + 𝑛) 0 ⟺ (⧺) ∷ [α] → [α] → [α] ⧺ 𝑦𝑠 = 𝑦𝑠 𝑥 ∶ 𝑥𝑠 ⧺ 𝑦𝑠 = 𝑥 ∶ (𝑥𝑠 ⧺ 𝑦𝑠) (⧺ 𝑦𝑠) = 𝑓𝑜𝑙𝑑 ∶ 𝑦𝑠 ⟺ concat ∷ [ α ] → [α] concat = concat 𝑥𝑠 ∶ 𝑥𝑠𝑠 = 𝑥𝑠 ⧺ 𝑐𝑜𝑛𝑐𝑎𝑡 𝑥𝑠𝑠 ⟺ concat = 𝑓𝑜𝑙𝑑 (⧺) [ ]
  • 4. The Triad of 𝑚𝑎𝑝, 𝑓𝑖𝑙𝑡𝑒𝑟 and 𝑓𝑜𝑙𝑑 𝑚𝑎𝑝 λ The 𝑏𝑟𝑒𝑎𝑑, 𝑏𝑢𝑡𝑡𝑒𝑟, and 𝑗𝑎𝑚 of Functional Programming =
  • 5. 𝑔 = 𝑣 𝑔 𝑥 ∶ 𝑥𝑠 = 𝑓 𝑥 𝑔 𝑥𝑠 𝑚𝑎𝑝 ∷ 𝛼 → 𝛽 → 𝛼 → 𝛽 𝑚𝑎𝑝 𝑓 = 𝑚𝑎𝑝 𝑓 𝑥 ∶ 𝑥𝑠 = 𝑓 𝑥 ∶ 𝑚𝑎𝑝 𝑓 𝑥𝑠 𝑚𝑎𝑝 𝑓 = 𝑓𝑜𝑙𝑑𝑟 𝜆𝑥. 𝜆𝑥𝑠. 𝑓 𝑥 ∶ 𝑥𝑠 [ ] ⟺ 𝑓𝑖𝑙𝑡𝑒𝑟 ∷ (𝛼 → 𝐵𝑜𝑜𝑙) → 𝛼 → 𝑎 𝑓𝑖𝑙𝑡𝑒𝑟 p = 𝑓𝑖𝑙𝑡𝑒𝑟 p 𝑥 ∶ 𝑥𝑠 = 𝐢𝐟 𝑝 𝑥 𝐭𝐡𝐞𝐧 𝑥 ∶ 𝑓𝑖𝑙𝑡𝑒𝑟 p 𝑥𝑠 𝐞𝐥𝐬𝐞 𝑓𝑖𝑙𝑡𝑒𝑟 p 𝑥𝑠 𝑓𝑖𝑙𝑡𝑒𝑟 p = 𝑓𝑜𝑙𝑑𝑟 (𝜆𝑥. 𝜆𝑥𝑠. 𝐢𝐟 𝑝 𝑥 𝐭𝐡𝐞𝐧 𝑥 ∶ 𝑥𝑠 𝐞𝐥𝐬𝐞 𝑥𝑠) [ ] ⟺ 𝑔 = 𝑓𝑜𝑙𝑑𝑟 𝑓 𝑣 ⟺ 𝑚𝑎𝑝 λ 𝑓𝑜𝑙𝑑 =