SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
Formal Methods in
Software
Lecture 8. Category Theory
Vlad Patryshev
SCU
2014
In This Lecture
● functors and examples (diagrams; product; exponentiations);
● currying/yoneda lemma;
● example with integers/rationals;
● monad
Example: Parametric Class
trait List[A] extends Iterable[A] {
def map[A](f:A=>B):List[B]
}
Functor
Given categories A and B, a functor F: A → B
consists of mappings F: Obj(A) → Obj(B)
and F: Fun(A) → Fun(B) ,
so that
F(idX
)=idF(X)
and F(f∘g)=F(f)∘F(g)
More Examples
● A= 3 , B=Sets; what is a functor 3 → Sets?
Have to define: sets F(0), F(1), F(2); functions F(f), F(g), F(gf)
● Any f:X→Y in category C is a functor from 2 to C.
Cartesian Product is a Functor
Fix an object A.
X ↦ X×A is a functor.
How does it work on functions?
f:X→Y ↦ f×idA
: X×A → Y×A
+1 is a Functor
In Sets, take X ↦ X+1. f: X→Y ↦ (f+1): X+1 → Y+1
This functor is called Option[T].
Category of Categories
Take functors F:A→B, G:B→C; their composition H=G∘F is also a functor.
H(idX
) = G(F(idX
)) = G(idF(X)
) = idG(F(X))
H(p∘q) = G(F(p∘q)) = G(F(p)∘F(q)) = G(F(p)) ∘G(F(q)) = H(p) ∘H(q)
Identity functor IdA
:A→A Id(f) = f
Cat - a category of all categories.
No barber problems, nobody shaves nobody.
Exponential Functor
A, B - objects in category C. BA
- an object of functions from A to B, if such
exists.
E.g. in Set, {f:A→B}.
In Scala In Java (Guava) (https://code.google.com/p/guava-
libraries/wiki/FunctionalExplained)
trait Function[X,Y] {
def apply(x:X): Y
}
interface Function<X,Y> {
Y apply(X x);
}
val len:Function[String, Int] = _.length Function<String, Integer> lengthFunction = new
Function<String, Integer>() {
public Integer apply(String string) {
return string.length();
}
};
Define Exponential via Currying
In Set, f:A→CB
≡ f’:A×B→C
f(x)(b) = f’(x,b)
Very similar to P⊢(Q→R) ≡ P∧Q ⊢ R
Actually… it’s the same thing.
Take posets, for example, Boolean lattice,
where a×b ≡ min(a,b) /*see lecture 7*/ ≡ a∧b
a∧b ≤ c ≡ a ≤ (b→c)
Currying: Yoneda Lemma
Fun(A×B, C) ≡ Fun(A, CB
)
(Caveat: what is Fun? A set? It’s not always available as a set)
Example with Numbers
Category Z = (Z,≤); category Q = (Q,≤)
Inclusion iz
: Z ↣ Q - preserves order, so is a functor.
How about Q → Z? Upb: q ↦ Upb(q)
Upb(q) ≤ n /* this is in Z */ ≡ q ≤ n /* this is in Q */
Take composition q ↦ iZ
(Upb(q)), call it Mint.
We see two properties:
● q ≤ Mint(q)
● Mint(Mint(q)) ≤ Mint(q) /* actually equal */
Example with Lists
Category Scala
Take functor List.
We see two properties:
● singleton: X → List[X]
● flatten: List[List[X]] → List[X]
Do you see similarity?
Monad
* f:F(X)->G(X) is natural if for all p:X→ Y
Given a category C, an endofunctor M: C → C
is called a Monad if it has two features:
● unitX
: X → M(X)
● flattenX
: M(M(X)) → M(X)
These two functions should be natural*
References
http://www.amazon.com/Category-Computer-Scientists-Foundations-Computing/dp/0262660717
http://fundeps.com/tables/FromSemigroupToMonads.pdf
Wikipedia
Formal methods   8 - category theory (last one)

Contenu connexe

Tendances

Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
samthemonad
 
Integration+using+u-substitutions
Integration+using+u-substitutionsIntegration+using+u-substitutions
Integration+using+u-substitutions
tutorcircle1
 
Lesson 28: The Fundamental Theorem of Calculus
Lesson 28: The Fundamental Theorem of CalculusLesson 28: The Fundamental Theorem of Calculus
Lesson 28: The Fundamental Theorem of Calculus
Matthew Leingang
 

Tendances (20)

Advanced matlab codigos matematicos
Advanced matlab codigos matematicosAdvanced matlab codigos matematicos
Advanced matlab codigos matematicos
 
Automatic variational inference with latent categorical variables
Automatic variational inference with latent categorical variablesAutomatic variational inference with latent categorical variables
Automatic variational inference with latent categorical variables
 
Abstract Algebra in 3 Hours
Abstract Algebra in 3 HoursAbstract Algebra in 3 Hours
Abstract Algebra in 3 Hours
 
Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
 
Functions
FunctionsFunctions
Functions
 
mathematical functions
mathematical functions mathematical functions
mathematical functions
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskell
 
Refresher algebra-calculus
Refresher algebra-calculusRefresher algebra-calculus
Refresher algebra-calculus
 
3.2 Derivative as a Function
3.2 Derivative as a Function3.2 Derivative as a Function
3.2 Derivative as a Function
 
Reading Seminar (140515) Spectral Learning of L-PCFGs
Reading Seminar (140515) Spectral Learning of L-PCFGsReading Seminar (140515) Spectral Learning of L-PCFGs
Reading Seminar (140515) Spectral Learning of L-PCFGs
 
Functionsandpigeonholeprinciple
FunctionsandpigeonholeprincipleFunctionsandpigeonholeprinciple
Functionsandpigeonholeprinciple
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
 
Integration+using+u-substitutions
Integration+using+u-substitutionsIntegration+using+u-substitutions
Integration+using+u-substitutions
 
Rules of Derivative
Rules of Derivative Rules of Derivative
Rules of Derivative
 
Website designing company in delhi ncr
Website designing company in delhi ncrWebsite designing company in delhi ncr
Website designing company in delhi ncr
 
Ch03
Ch03Ch03
Ch03
 
Cheatsheet supervised-learning
Cheatsheet supervised-learningCheatsheet supervised-learning
Cheatsheet supervised-learning
 
Regression_1.pdf
Regression_1.pdfRegression_1.pdf
Regression_1.pdf
 
Lesson 28: The Fundamental Theorem of Calculus
Lesson 28: The Fundamental Theorem of CalculusLesson 28: The Fundamental Theorem of Calculus
Lesson 28: The Fundamental Theorem of Calculus
 

En vedette

Scalable Data Science and Deep Learning with H2O
Scalable Data Science and Deep Learning with H2OScalable Data Science and Deep Learning with H2O
Scalable Data Science and Deep Learning with H2O
odsc
 
H2O Distributed Deep Learning by Arno Candel 071614
H2O Distributed Deep Learning by Arno Candel 071614H2O Distributed Deep Learning by Arno Candel 071614
H2O Distributed Deep Learning by Arno Candel 071614
Sri Ambati
 

En vedette (11)

Scalable Data Science and Deep Learning with H2O
Scalable Data Science and Deep Learning with H2OScalable Data Science and Deep Learning with H2O
Scalable Data Science and Deep Learning with H2O
 
H2O.ai - Road Ahead - keynote presentation by Sri Ambati
H2O.ai - Road Ahead - keynote presentation by Sri AmbatiH2O.ai - Road Ahead - keynote presentation by Sri Ambati
H2O.ai - Road Ahead - keynote presentation by Sri Ambati
 
Data Science, Machine Learning, and H2O
Data Science, Machine Learning, and H2OData Science, Machine Learning, and H2O
Data Science, Machine Learning, and H2O
 
H2O Big Data Environments
H2O Big Data EnvironmentsH2O Big Data Environments
H2O Big Data Environments
 
Sparkling Water 2.0 - Michal Malohlava
Sparkling Water 2.0 - Michal MalohlavaSparkling Water 2.0 - Michal Malohlava
Sparkling Water 2.0 - Michal Malohlava
 
Build Your Own Recommendation Engine
Build Your Own Recommendation EngineBuild Your Own Recommendation Engine
Build Your Own Recommendation Engine
 
Deep Water - GPU Deep Learning for H2O - Arno Candel
Deep Water - GPU Deep Learning for H2O - Arno CandelDeep Water - GPU Deep Learning for H2O - Arno Candel
Deep Water - GPU Deep Learning for H2O - Arno Candel
 
H2O PySparkling Water
H2O PySparkling WaterH2O PySparkling Water
H2O PySparkling Water
 
H2O AutoML roadmap - Ray Peck
H2O AutoML roadmap - Ray PeckH2O AutoML roadmap - Ray Peck
H2O AutoML roadmap - Ray Peck
 
Intro to Machine Learning with H2O and AWS
Intro to Machine Learning with H2O and AWSIntro to Machine Learning with H2O and AWS
Intro to Machine Learning with H2O and AWS
 
H2O Distributed Deep Learning by Arno Candel 071614
H2O Distributed Deep Learning by Arno Candel 071614H2O Distributed Deep Learning by Arno Candel 071614
H2O Distributed Deep Learning by Arno Candel 071614
 

Similaire à Formal methods 8 - category theory (last one)

01. Functions-Theory & Solved Examples Module-4.pdf
01. Functions-Theory & Solved Examples Module-4.pdf01. Functions-Theory & Solved Examples Module-4.pdf
01. Functions-Theory & Solved Examples Module-4.pdf
RajuSingh806014
 
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
7anantsharma7
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
Meetu Maltiar
 
02-Basic Structures .ppt
02-Basic Structures .ppt02-Basic Structures .ppt
02-Basic Structures .ppt
Acct4
 

Similaire à Formal methods 8 - category theory (last one) (20)

Fp in scala with adts part 2
Fp in scala with adts part 2Fp in scala with adts part 2
Fp in scala with adts part 2
 
Introductory part of function for class 12th JEE
Introductory part of function for class 12th JEEIntroductory part of function for class 12th JEE
Introductory part of function for class 12th JEE
 
Algebras for programming languages
Algebras for programming languagesAlgebras for programming languages
Algebras for programming languages
 
Chap4
Chap4Chap4
Chap4
 
Pertemuan 3
Pertemuan 3Pertemuan 3
Pertemuan 3
 
Prerequisite for metric space
Prerequisite for metric spacePrerequisite for metric space
Prerequisite for metric space
 
Hay hay
Hay hayHay hay
Hay hay
 
Functions
FunctionsFunctions
Functions
 
Funcionesreales 160109205602
Funcionesreales 160109205602Funcionesreales 160109205602
Funcionesreales 160109205602
 
01. Functions-Theory & Solved Examples Module-4.pdf
01. Functions-Theory & Solved Examples Module-4.pdf01. Functions-Theory & Solved Examples Module-4.pdf
01. Functions-Theory & Solved Examples Module-4.pdf
 
TYPES OF FUNCTION FOR JEE PREPARATION WITH EXAMPLES
TYPES OF FUNCTION FOR JEE PREPARATION WITH EXAMPLESTYPES OF FUNCTION FOR JEE PREPARATION WITH EXAMPLES
TYPES OF FUNCTION FOR JEE PREPARATION WITH EXAMPLES
 
The integral
The integralThe integral
The integral
 
Hyperfunction method for numerical integration and Fredholm integral equation...
Hyperfunction method for numerical integration and Fredholm integral equation...Hyperfunction method for numerical integration and Fredholm integral equation...
Hyperfunction method for numerical integration and Fredholm integral equation...
 
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Aa4
Aa4Aa4
Aa4
 
Introductory calculus
Introductory calculusIntroductory calculus
Introductory calculus
 
02-Basic Structures .ppt
02-Basic Structures .ppt02-Basic Structures .ppt
02-Basic Structures .ppt
 
Complex Analysis And ita real life problems solution
Complex Analysis And ita real life problems solutionComplex Analysis And ita real life problems solution
Complex Analysis And ita real life problems solution
 

Plus de Vlad Patryshev

Plus de Vlad Patryshev (20)

Formal methods 6 - elements of algebra
Formal methods   6 - elements of algebraFormal methods   6 - elements of algebra
Formal methods 6 - elements of algebra
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introduction
 
Formal methods 7 - category theory
Formal methods   7 - category theoryFormal methods   7 - category theory
Formal methods 7 - category theory
 
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation   lecture i (last one)Truth, deduction, computation   lecture i (last one)
Truth, deduction, computation lecture i (last one)
 
Truth, deduction, computation lecture h
Truth, deduction, computation   lecture hTruth, deduction, computation   lecture h
Truth, deduction, computation lecture h
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture g
 
Truth, deduction, computation lecture f
Truth, deduction, computation   lecture fTruth, deduction, computation   lecture f
Truth, deduction, computation lecture f
 
Truth, deduction, computation lecture e
Truth, deduction, computation   lecture eTruth, deduction, computation   lecture e
Truth, deduction, computation lecture e
 
Truth, deduction, computation lecture d
Truth, deduction, computation   lecture dTruth, deduction, computation   lecture d
Truth, deduction, computation lecture d
 
Truth, deduction, computation lecture c
Truth, deduction, computation   lecture cTruth, deduction, computation   lecture c
Truth, deduction, computation lecture c
 
Truth, deduction, computation lecture b
Truth, deduction, computation   lecture bTruth, deduction, computation   lecture b
Truth, deduction, computation lecture b
 
Truth, deduction, computation lecture a
Truth, deduction, computation   lecture aTruth, deduction, computation   lecture a
Truth, deduction, computation lecture a
 
Truth, deduction, computation lecture 9
Truth, deduction, computation   lecture 9Truth, deduction, computation   lecture 9
Truth, deduction, computation lecture 9
 
Truth, deduction, computation lecture 8
Truth, deduction, computation   lecture 8Truth, deduction, computation   lecture 8
Truth, deduction, computation lecture 8
 
Truth, deduction, computation lecture 7
Truth, deduction, computation   lecture 7Truth, deduction, computation   lecture 7
Truth, deduction, computation lecture 7
 
Truth, deduction, computation lecture 6
Truth, deduction, computation   lecture 6Truth, deduction, computation   lecture 6
Truth, deduction, computation lecture 6
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5
 
Truth, deduction, computation; lecture 4
Truth, deduction, computation;  lecture 4Truth, deduction, computation;  lecture 4
Truth, deduction, computation; lecture 4
 
Truth, deduction, computation; lecture 3
Truth, deduction, computation;  lecture 3Truth, deduction, computation;  lecture 3
Truth, deduction, computation; lecture 3
 
Truth, deduction, computation; lecture 2
Truth, deduction, computation;   lecture 2Truth, deduction, computation;   lecture 2
Truth, deduction, computation; lecture 2
 

Dernier

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Dernier (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

Formal methods 8 - category theory (last one)

  • 1. Formal Methods in Software Lecture 8. Category Theory Vlad Patryshev SCU 2014
  • 2. In This Lecture ● functors and examples (diagrams; product; exponentiations); ● currying/yoneda lemma; ● example with integers/rationals; ● monad
  • 3. Example: Parametric Class trait List[A] extends Iterable[A] { def map[A](f:A=>B):List[B] }
  • 4. Functor Given categories A and B, a functor F: A → B consists of mappings F: Obj(A) → Obj(B) and F: Fun(A) → Fun(B) , so that F(idX )=idF(X) and F(f∘g)=F(f)∘F(g)
  • 5. More Examples ● A= 3 , B=Sets; what is a functor 3 → Sets? Have to define: sets F(0), F(1), F(2); functions F(f), F(g), F(gf) ● Any f:X→Y in category C is a functor from 2 to C.
  • 6. Cartesian Product is a Functor Fix an object A. X ↦ X×A is a functor. How does it work on functions? f:X→Y ↦ f×idA : X×A → Y×A
  • 7. +1 is a Functor In Sets, take X ↦ X+1. f: X→Y ↦ (f+1): X+1 → Y+1 This functor is called Option[T].
  • 8. Category of Categories Take functors F:A→B, G:B→C; their composition H=G∘F is also a functor. H(idX ) = G(F(idX )) = G(idF(X) ) = idG(F(X)) H(p∘q) = G(F(p∘q)) = G(F(p)∘F(q)) = G(F(p)) ∘G(F(q)) = H(p) ∘H(q) Identity functor IdA :A→A Id(f) = f Cat - a category of all categories. No barber problems, nobody shaves nobody.
  • 9. Exponential Functor A, B - objects in category C. BA - an object of functions from A to B, if such exists. E.g. in Set, {f:A→B}. In Scala In Java (Guava) (https://code.google.com/p/guava- libraries/wiki/FunctionalExplained) trait Function[X,Y] { def apply(x:X): Y } interface Function<X,Y> { Y apply(X x); } val len:Function[String, Int] = _.length Function<String, Integer> lengthFunction = new Function<String, Integer>() { public Integer apply(String string) { return string.length(); } };
  • 10. Define Exponential via Currying In Set, f:A→CB ≡ f’:A×B→C f(x)(b) = f’(x,b) Very similar to P⊢(Q→R) ≡ P∧Q ⊢ R Actually… it’s the same thing. Take posets, for example, Boolean lattice, where a×b ≡ min(a,b) /*see lecture 7*/ ≡ a∧b a∧b ≤ c ≡ a ≤ (b→c)
  • 11. Currying: Yoneda Lemma Fun(A×B, C) ≡ Fun(A, CB ) (Caveat: what is Fun? A set? It’s not always available as a set)
  • 12. Example with Numbers Category Z = (Z,≤); category Q = (Q,≤) Inclusion iz : Z ↣ Q - preserves order, so is a functor. How about Q → Z? Upb: q ↦ Upb(q) Upb(q) ≤ n /* this is in Z */ ≡ q ≤ n /* this is in Q */ Take composition q ↦ iZ (Upb(q)), call it Mint. We see two properties: ● q ≤ Mint(q) ● Mint(Mint(q)) ≤ Mint(q) /* actually equal */
  • 13. Example with Lists Category Scala Take functor List. We see two properties: ● singleton: X → List[X] ● flatten: List[List[X]] → List[X] Do you see similarity?
  • 14. Monad * f:F(X)->G(X) is natural if for all p:X→ Y Given a category C, an endofunctor M: C → C is called a Monad if it has two features: ● unitX : X → M(X) ● flattenX : M(M(X)) → M(X) These two functions should be natural*
  • 15.