SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Philip Schwarz

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

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

Kürzlich hochgeladen

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
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
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
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
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Kürzlich hochgeladen (20)

Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
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 ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
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
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

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 = 𝑓𝑜𝑙𝑑𝑟 (𝜆𝑥. 𝜆𝑥𝑠. 𝐢𝐟 𝑝 𝑥 𝐭𝐡𝐞𝐧 𝑥 ∶ 𝑥𝑠 𝐞𝐥𝐬𝐞 𝑥𝑠) [ ] ⟺ 𝑔 = 𝑓𝑜𝑙𝑑𝑟 𝑓 𝑣 ⟺ 𝑚𝑎𝑝 λ 𝑓𝑜𝑙𝑑 =