SlideShare a Scribd company logo
Expressiveness and
Model of the
Polymorphic λ Calculus
Shin-Cheng Mu
IIS, Sinica
Friday, April 11, 14
Motivation
• V. Vene in APLAS 2004 [GUV04] gave a new
proof of shortcut deforestation because it was
only proved “informally by theorem-for free.”
• But what’s wrong with theorem for free?
• So I studied polymorphism and realised that
there is a lot I did not know...
Friday, April 11, 14
Parametricity, or the
“theorems for free.”
• Informally known by functional programmers
as the “theorems for free.”
• A polymorphic function’s type induces a
“theorem”.
• E.g. hd . map f = f . hd, for all hd:: [a]→a,
regradless of its actual definition.
• The word “theorem” may be mis-leading,
however.
[Wad89]
Friday, April 11, 14
In this talk
• Review some members of the λ calculus
family:
• Untyped λ calculus: λx . x
• Simply-typed λ calculus: λx:Int . x
• Polymorphic λ calculus: Λα.(λx:α . x),
Δα.α--->τ, f [a] x
• Consider their termination property,
expressiveness, and model.
Friday, April 11, 14
Untyped λ calculus
• Not always terminating: (λx.(x x))(λx.(x x))
• Recursion: Y f = (λx . f (x x))(λx . f (x x))
• Equivalent to Turing machine (Church &
Kleene).
• Denotational model not trivial: requires Scott
domains.
Friday, April 11, 14
Simply-typed λ calculus
• Strongly normalisable: all well-typed
expression terminates. Y combinator cannot
be typed.
• Computes total functions only!
• Has a simple model of total functions and
sets.
• Apparently cannot define some useful
functions. But exactly how expressive?
Friday, April 11, 14
The computability hierarchy
partial recursive (functions)
total recursive
primitive recursive
elementry recursive
Friday, April 11, 14
Primitive recursion
• A function that can be implemented using
only for-loops (math world). It always
terminate.
• Zero: 0, succ: (1+), projection: (x1,...,xn)= xi.
• Composition: f o g.
• Primitive recursion:
h(0,x) = f(x)
h(n+1,x) = g (h(n),n,x)
Friday, April 11, 14
Primitive recursion
• A function that can be implemented using
only for-loops (math world). It always
terminate.
• Zero: 0, succ: (1+), projection: (x1,...,xn)= xi.
• Composition: f o g.
• Primitive recursion:
h(0,x) = f(x)
h(n+1,x) = g (h(n),n,x)
h(0) = c
h(n+1) = g (h(n),n)
Familiar? It’s paramorphism! [Mee90]
Friday, April 11, 14
Partial and total recursion
• Partial recursive functions: primitive
recursion plus unbounded search:
μf z = least x such that f(x,z) = 0.
• The search may not terminate, thus
introduces the partiality.
• Partial rec. fn. is equiv. to Turing machine.
• Total recursive functions: the subset of parital
rec. fn. that is total. It’s bigger than primitive
recursive functions! (eg. Ackermann’s
function.)
Friday, April 11, 14
Elementary recursion
• Also called Kalmar elementary functions. 
Functions definable by 1, +, x, -., and
 SUM f (x,n) = Σn
i=0
f(x,i)
 PRO f (x,n) = Πn
i=0
f(x,i)
• Definable functions include: mod, div,
isPrime, etc.
Friday, April 11, 14
Representing natural num.
• Rep. of n over domain τ:
λf:τ--->τ . λx:τ . f (... (f x)) with n occur. of f.
• If we allow different instantiation of τ, we
can define addition, multiplication, exp(Ii+1-->
Ii---> Ii), predecessor(Ii+3---> Ii)... but not
subtraction.
• Therefore simply-typed calculus is weaker
than elementary functions. Moreover, its
value is bound by elementary fns.
Friday, April 11, 14
• Use the type Δα.(α--->α)--->(α--->α) to
represent natural numbers.
• addition, multiplication, subtraction,pairs,..
• primrec = Δα.λg:N--->α--->α.λc:α.
λn:N.snd(n[Nxα]
(λz:Nxα.<1+fst z,g (fst z) (snd z)>) <0,c>)
Polymorphism enhances
expressiveness
Friday, April 11, 14
• Use the type Δα.(α--->α)--->(α--->α) to
represent natural numbers.
• addition, multiplication, subtraction,pairs,..
• primrec = Δα.λg:N--->α--->α.λc:α.
λn:N.snd(n[Nxα]
(λz:Nxα.<1+fst z,g (fst z) (snd z)>) <0,c>)
Polymorphism enhances
expressiveness
primrec = Δα.λg.λc.
λn.snd
(n (λz.<1+fst z,g (fst z) (snd z)>) <0,c>)
Friday, April 11, 14
Ackermann’s function!
Define ack
without recursion?
[Rey85]
ack 0 n = n+1
ack (m+1) 0 = ack m 1
ack (m+1) (n+1) = ack m (ack (m+1) n)
• Guess: ack = λm. m aug (1+)
therefore ack (m+1) = aug (ack m)
• ack (m+1) (n+1) = aug (ack m) (n+1) =
ack m (aug (ack m) n) = ack m (ack (m+1) n)
• We want aug f 0 = f 1 and
aug f (n+1) = f (aug f n)
• Solution: aug = λf. λn. (n+1) f 1
Friday, April 11, 14
Simulating data structures
• Let list a = Δβ.(a--->β--->β) ---> β ---> β
nil = Λβ.λf.λa.a
cons x xs = Λβ.λf.λa. f x (xs f a)
• append xs ys = xs cons ys
• append = λxs:list a. λys:list a .
xs[list a] (λx:a.λzs:list a . cons x zs) ys
[Rey85]
Friday, April 11, 14
Simulating data structures
• Let list a = Δβ.(a--->β--->β) ---> β ---> β
nil = Λβ.λf.λa.a
cons x xs = Λβ.λf.λa. f x (xs f a)
• append xs ys = xs cons ys
• append = λxs:list a. λys:list a .
xs[list a] (λx:a.λzs:list a . cons x zs) ys
! nil = Λβ.λf:a--->β--->β.λa:a.a
cons x xs = Λβ.λf:a--->β--->β.λa:a. f x (xs f a)
[Rey85]
Friday, April 11, 14
Where does it stand?
partial recursive (functions)
total recursive
primitive recursive
elementry recursive
Polymorphic λ
Simply-typed λ
Friday, April 11, 14
Fundamental sequence
• Define f0(x) = x+1
• fn+1(x)= fx
n(x) = fn(fn...(fn(x))..)... x
applications.
• f1(x)=2x, f2(x)=2x
×x
• fΘ(x)=fΘ[x](x) for limit ordinal Θ.
• Limit ordinals: ω is the size of natural
numbers, ε0 is the limit of ω, ωω
, ωωω
.....
Friday, April 11, 14
Hierarchy characterised by
rate of growth
• Running time of elementary functions are
bounded by fn
2(x) for some n.
• Time of primitive recursive functions are
bounded by fn(x) for some n< ω.
• Ackermann’s function is essentially fω(x).
• fε0(x) is representable in polymorphic λ
calculus!
• It represents exactly the functions provably
recursive in 2nd-order arithmetic -- a much
larger class than fε0(x).
[FLD83]
Friday, April 11, 14
Termination
• Still, every function defined in poly-λ
terminates.
• However, the termination cannot be proved
in Peano arithmetic!
• Peano arithmetic: 0, (1+), addition,
induction... covering most techniques we
use in proofs of programs.
• Godel’s incompleteness theorem stated that
there are true theorems not provable in PA.
This was the first “interesting” example.
[FLD83]
Friday, April 11, 14
Model for poly. λ calculus?
• Untyped λ: not terminating, needs domain.
• Simple-typed λ: terminating, set-theoretic.
• λx:Int.x is the id for Int, λx:Char.x for Char.
• Poly. λ: can we avoid using domains?
• First try: a polymorphic function is a
collection of functions indexed by type.
• Λα.λx:α.x is a collection of identity fns.
• However, that would include some ad-hoc
functions.
Friday, April 11, 14
Parametricity
• Reynolds restricts polymorphic objects to
parametric values:
• Let p: Δα.τ. It is parametric if for all set
assignments s1, s2, and r s1×s2:
	 	 	 	 〈p s1, p s2〉 [id|α:r]#
τ
• Which later became “theorem for free”.
• Reynolds [Rey83] believed that there is a set-
theoretic model for poly. λ where poly.
objects represent parametric values.
• He then falsified his conjecture [Rey84].
[Wad89]
Friday, April 11, 14
No simple model!
• Bool can be represented by B=Δα.α--->α--->α
• Let Ts = (s--->B)--->B for all type s, and Tf =
λh.λg.h(g o f) (for all f: s--->t, Tf: Ts--->Tt).
• Let P=(((s--->B)--->B)--->s)--->s. We can construct a
h: TP--->P s.t. the diagram commutes for all f.
• In fact h is an initial algebra!
• But that would make TP isomorphic to P,
which is a contradiction (they have diff.
cardinalities unless |B|=1).
h
P TP
s Ts
Tgg
f
[Rey84]Polymor
phism is not
set-theoretic.
f. g.
Friday, April 11, 14
Later models
• Using topos [Pit87]Poly. is set-theoretic, constructively.
• Frame [BM84][MM85][Wad89].
• Functorial approach [BFS90].
• Operational aspects [Pit00].
• Used to prove short-cut fusion [Joh03].
Friday, April 11, 14
What’s the use of
parametricity?
• It’s still a key concept! Recall representation
of lists: llist a = Δβ.(a--->β--->β) ---> β ---> β.
• In general, the least fixed-point of functor F
(or the inital F-algebra) can be represented by
Δβ.(F β--->β) ---> β... iff parametricity holds!
• Types defined as least-fixed-points are called
inductive.
• nil = Λβ.λf.λa.a, cons x xs = Λβ.λf.λa. f x
(xs f a), x = cons 1 (cons 2 (cons 3 nil).
[Has94]
Friday, April 11, 14
Inductive and coinductive
datatypes
• The greatest fixed-point of functor F can be
represented by ∃x.(x → F x, x), iff
parametricity holds. It’s called coinductive.
• from n = (λm.Right (m,m+1), n) :: glist a
• When least and greatest fixed-points
coincide (i.e. exists a force:: glist a →llist a),
we can do hylomorphism.
[Has94]
[How96]
Friday, April 11, 14
Pointed types
• In a model where parametricity and
extensionality holds, the following are
equivalent:
• Inductive and coinductive types coincide;
• Exists a fixed-point operator for values;
• Exists a fixed-point operator for types.
[Has94] ?
Friday, April 11, 14
Conclusion
Termination Expressiveness Model
Untyped NO = Turing
machine
domain
Simply typed YES < elementry fn. set &
functio
n
Polymorphic
YES but not
provable in
PA
> Ackermann
domain or
non-trivial
sets
Friday, April 11, 14
What I learnt from this history
study...
• Adding polymorphism to a language strongly
enhances its power.
• The concept of fold, etc., finds its root in very
fundamental research.
• Category theory has played an important
role in early stage of computing science.
• Parametricity is an important assumption
leading to many useful properties.
Friday, April 11, 14
References
• [FLD83] S.Fortune, D. Leivant, M. O’Donnell, The expressiveness of
simple and second-order type structures. In Journal of the ACM, 30(1), pp
151-185.
• [Rey83] J.C. Reynolds. Types, abstractions and parametric polymorphism.
In Information Processing 83, pp 513-523.
• [BM84]K.B. Bruce, A.R. Meyer, The semantics of second-order
polymorphic lambda calculus. In Semantics of Data Types, LNCS 173.
• [Rey84] J.C. Reynolds, Polymorphism is not set theoretic. In Semantics of
data Types, LNCS 173, pp 145-156.
• [MM85] J.C. Mitchell, A.R. Meyer, Second-order logical relations. In
Logics of Programs, LNCS 193.
• [Rey85] J.C. Reynolds, Three approaches to type structure. In
Mathematical Foundations of Software Development, LNCS 185.
Friday, April 11, 14
References
• [Pit87] A.M. Pitts, Polymorphism is set theoretic, constructively. In
Category Theory and Computer Science, LNCS 283, pp 12-39.
• [Wad89] P. Wadler, Theorems for free! In Int. Sym. on Functional
Programming Languages and Computer Architecture, ‘89.
• [BFS90] E.S. Bainbridge, P.J. Freyd, A. Scedrov, P.J. Scott, Functorial
polymorphism. In Theoretical computer science v.70, pp 36-54.
• [Mee90] L. Meertens, Paramorphisms. In Formal Aspects of Computing.
• [Has94] R. Hasegawa. Categorical data types in parametric
polymorphism. Math. Structures in Computer Science, March 1994.
• [How96] B.T. Howard. Inductive, coinductive, and pointed types. ICFP 96.
• [Pit00] A.M. Pitts, Parametric polymorphism and operational equivalence.
In Math. Struct. in Comp. Science v.10, pp 1-39.
• [Joh03] P. Johann, Short cut fusion is correct. In J. Functional Programming
v.13, pp 797-814.
• [GUV04]N. Ghani, T. Uustalu, V, Vene, Build, augment and destory. In
APLAS 2004, LNCS 3002, pp 327-347.
Friday, April 11, 14

More Related Content

What's hot

Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Matthew Leingang
 
Otter 2016-11-28-01-ss
Otter 2016-11-28-01-ssOtter 2016-11-28-01-ss
Otter 2016-11-28-01-ss
Ruo Ando
 
ma112011id535
ma112011id535ma112011id535
ma112011id535
matsushimalab
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Runtime Analysis of Population-based Evolutionary Algorithms
Runtime Analysis of Population-based Evolutionary AlgorithmsRuntime Analysis of Population-based Evolutionary Algorithms
Runtime Analysis of Population-based Evolutionary Algorithms
PK Lehre
 
01. haskell introduction
01. haskell introduction01. haskell introduction
01. haskell introduction
Sebastian Rettig
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
Software Guru
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculus
Vlad Patryshev
 
[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell
Functional Thursday
 
Prml
PrmlPrml
Prml
syou6162
 
Koc3(dba)
Koc3(dba)Koc3(dba)
Koc3(dba)
Serhat Yucel
 
Claire98
Claire98Claire98
Claire98
Yves Caseau
 
Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
samthemonad
 
PaperNo10-KaramiHabibiSafariZarrabi-IJCMS
PaperNo10-KaramiHabibiSafariZarrabi-IJCMSPaperNo10-KaramiHabibiSafariZarrabi-IJCMS
PaperNo10-KaramiHabibiSafariZarrabi-IJCMS
Mezban Habibi
 
Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)
Matthew Leingang
 
NumPy
NumPyNumPy
Pre- Operator Compact Space
Pre- Operator Compact SpacePre- Operator Compact Space
Pre- Operator Compact Space
iosrjce
 
Category Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) picturesCategory Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) pictures
Ashwin Rao
 
Introduction to Iteratees (Scala)
Introduction to Iteratees (Scala)Introduction to Iteratees (Scala)
Introduction to Iteratees (Scala)
Alexander Lehmann
 
Numpy
NumpyNumpy
Numpy
ToniyaP1
 

What's hot (20)

Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
 
Otter 2016-11-28-01-ss
Otter 2016-11-28-01-ssOtter 2016-11-28-01-ss
Otter 2016-11-28-01-ss
 
ma112011id535
ma112011id535ma112011id535
ma112011id535
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Runtime Analysis of Population-based Evolutionary Algorithms
Runtime Analysis of Population-based Evolutionary AlgorithmsRuntime Analysis of Population-based Evolutionary Algorithms
Runtime Analysis of Population-based Evolutionary Algorithms
 
01. haskell introduction
01. haskell introduction01. haskell introduction
01. haskell introduction
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculus
 
[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell
 
Prml
PrmlPrml
Prml
 
Koc3(dba)
Koc3(dba)Koc3(dba)
Koc3(dba)
 
Claire98
Claire98Claire98
Claire98
 
Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
 
PaperNo10-KaramiHabibiSafariZarrabi-IJCMS
PaperNo10-KaramiHabibiSafariZarrabi-IJCMSPaperNo10-KaramiHabibiSafariZarrabi-IJCMS
PaperNo10-KaramiHabibiSafariZarrabi-IJCMS
 
Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)
 
NumPy
NumPyNumPy
NumPy
 
Pre- Operator Compact Space
Pre- Operator Compact SpacePre- Operator Compact Space
Pre- Operator Compact Space
 
Category Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) picturesCategory Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) pictures
 
Introduction to Iteratees (Scala)
Introduction to Iteratees (Scala)Introduction to Iteratees (Scala)
Introduction to Iteratees (Scala)
 
Numpy
NumpyNumpy
Numpy
 

Viewers also liked

Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
Dave Fancher
 
Unusual Toy
Unusual ToyUnusual Toy
Unusual Toy
LindVera
 
Elements of functional programming
Elements of functional programmingElements of functional programming
Elements of functional programming
Sajjad Ali Pulikkanat
 
Faking it
Faking itFaking it
Faking it
Dave Fancher
 
59fifty ppt
59fifty ppt59fifty ppt
59fifty ppt
bucknasty3333
 
French Revolution
French Revolution French Revolution
French Revolution
Himanshu Jain
 

Viewers also liked (6)

Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
 
Unusual Toy
Unusual ToyUnusual Toy
Unusual Toy
 
Elements of functional programming
Elements of functional programmingElements of functional programming
Elements of functional programming
 
Faking it
Faking itFaking it
Faking it
 
59fifty ppt
59fifty ppt59fifty ppt
59fifty ppt
 
French Revolution
French Revolution French Revolution
French Revolution
 

Similar to Expressiveness and Model of the Polymorphic λ Calculus

Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional Programming
Filip De Sutter
 
Basic Knowledge Representation in First Order Logic.ppt
Basic Knowledge Representation in First Order Logic.pptBasic Knowledge Representation in First Order Logic.ppt
Basic Knowledge Representation in First Order Logic.ppt
AshfaqAhmed693399
 
dfgsdfdsgdfgfdgdrgdfgffdhyrthfgnhgjhgdfs.ppt
dfgsdfdsgdfgfdgdrgdfgffdhyrthfgnhgjhgdfs.pptdfgsdfdsgdfgfdgdrgdfgffdhyrthfgnhgjhgdfs.ppt
dfgsdfdsgdfgfdgdrgdfgffdhyrthfgnhgjhgdfs.ppt
NobitaNobi489694
 
Lesson 23: Antiderivatives (slides)
Lesson 23: Antiderivatives (slides)Lesson 23: Antiderivatives (slides)
Lesson 23: Antiderivatives (slides)
Mel Anthony Pepito
 
Dirichlet processes and Applications
Dirichlet processes and ApplicationsDirichlet processes and Applications
Dirichlet processes and Applications
Saurav Jha
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
goncharenko
 
IVR - Chapter 1 - Introduction
IVR - Chapter 1 - IntroductionIVR - Chapter 1 - Introduction
IVR - Chapter 1 - Introduction
Charles Deledalle
 
Algorithms and Complexity: Cryptography Theory
Algorithms and Complexity: Cryptography TheoryAlgorithms and Complexity: Cryptography Theory
Algorithms and Complexity: Cryptography Theory
Alex Prut
 
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
The Statistical and Applied Mathematical Sciences Institute
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
baran19901990
 
Newton raphson method
Newton raphson methodNewton raphson method
Newton raphson method
Bijay Mishra
 
Function Basics Math Wiki
Function Basics   Math WikiFunction Basics   Math Wiki
Function Basics Math Wiki
Alec Kargodorian
 
Lesson 1: Functions
Lesson 1: FunctionsLesson 1: Functions
Lesson 1: Functions
Matthew Leingang
 
Introduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdfIntroduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdf
JifarRaya
 
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Mel Anthony Pepito
 
Discrete Structure Lecture #5 & 6.pdf
Discrete Structure Lecture #5 & 6.pdfDiscrete Structure Lecture #5 & 6.pdf
Discrete Structure Lecture #5 & 6.pdf
MuhammadUmerIhtisham
 
Ml mle_bayes
Ml  mle_bayesMl  mle_bayes
Ml mle_bayes
Phong Vo
 
Newton raphsonmethod presentation
Newton raphsonmethod presentationNewton raphsonmethod presentation
Newton raphsonmethod presentation
Abdullah Moin
 
Universal Approximation Theorem
Universal Approximation TheoremUniversal Approximation Theorem
Universal Approximation Theorem
Jamie Seol
 
Module_5_1.pptx
Module_5_1.pptxModule_5_1.pptx
Module_5_1.pptx
DrKalaavathiBuvanesh
 

Similar to Expressiveness and Model of the Polymorphic λ Calculus (20)

Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional Programming
 
Basic Knowledge Representation in First Order Logic.ppt
Basic Knowledge Representation in First Order Logic.pptBasic Knowledge Representation in First Order Logic.ppt
Basic Knowledge Representation in First Order Logic.ppt
 
dfgsdfdsgdfgfdgdrgdfgffdhyrthfgnhgjhgdfs.ppt
dfgsdfdsgdfgfdgdrgdfgffdhyrthfgnhgjhgdfs.pptdfgsdfdsgdfgfdgdrgdfgffdhyrthfgnhgjhgdfs.ppt
dfgsdfdsgdfgfdgdrgdfgffdhyrthfgnhgjhgdfs.ppt
 
Lesson 23: Antiderivatives (slides)
Lesson 23: Antiderivatives (slides)Lesson 23: Antiderivatives (slides)
Lesson 23: Antiderivatives (slides)
 
Dirichlet processes and Applications
Dirichlet processes and ApplicationsDirichlet processes and Applications
Dirichlet processes and Applications
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
IVR - Chapter 1 - Introduction
IVR - Chapter 1 - IntroductionIVR - Chapter 1 - Introduction
IVR - Chapter 1 - Introduction
 
Algorithms and Complexity: Cryptography Theory
Algorithms and Complexity: Cryptography TheoryAlgorithms and Complexity: Cryptography Theory
Algorithms and Complexity: Cryptography Theory
 
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Newton raphson method
Newton raphson methodNewton raphson method
Newton raphson method
 
Function Basics Math Wiki
Function Basics   Math WikiFunction Basics   Math Wiki
Function Basics Math Wiki
 
Lesson 1: Functions
Lesson 1: FunctionsLesson 1: Functions
Lesson 1: Functions
 
Introduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdfIntroduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdf
 
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
Lesson 14: Derivatives of Logarithmic and Exponential Functions (slides)
 
Discrete Structure Lecture #5 & 6.pdf
Discrete Structure Lecture #5 & 6.pdfDiscrete Structure Lecture #5 & 6.pdf
Discrete Structure Lecture #5 & 6.pdf
 
Ml mle_bayes
Ml  mle_bayesMl  mle_bayes
Ml mle_bayes
 
Newton raphsonmethod presentation
Newton raphsonmethod presentationNewton raphsonmethod presentation
Newton raphsonmethod presentation
 
Universal Approximation Theorem
Universal Approximation TheoremUniversal Approximation Theorem
Universal Approximation Theorem
 
Module_5_1.pptx
Module_5_1.pptxModule_5_1.pptx
Module_5_1.pptx
 

Recently uploaded

Shallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptxShallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptx
Gokturk Mehmet Dilci
 
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
University of Maribor
 
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
yqqaatn0
 
Bob Reedy - Nitrate in Texas Groundwater.pdf
Bob Reedy - Nitrate in Texas Groundwater.pdfBob Reedy - Nitrate in Texas Groundwater.pdf
Bob Reedy - Nitrate in Texas Groundwater.pdf
Texas Alliance of Groundwater Districts
 
Deep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless ReproducibilityDeep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless Reproducibility
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
THEMATIC APPERCEPTION TEST(TAT) cognitive abilities, creativity, and critic...
THEMATIC  APPERCEPTION  TEST(TAT) cognitive abilities, creativity, and critic...THEMATIC  APPERCEPTION  TEST(TAT) cognitive abilities, creativity, and critic...
THEMATIC APPERCEPTION TEST(TAT) cognitive abilities, creativity, and critic...
Abdul Wali Khan University Mardan,kP,Pakistan
 
What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
moosaasad1975
 
Topic: SICKLE CELL DISEASE IN CHILDREN-3.pdf
Topic: SICKLE CELL DISEASE IN CHILDREN-3.pdfTopic: SICKLE CELL DISEASE IN CHILDREN-3.pdf
Topic: SICKLE CELL DISEASE IN CHILDREN-3.pdf
TinyAnderson
 
SAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdfSAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdf
KrushnaDarade1
 
Medical Orthopedic PowerPoint Templates.pptx
Medical Orthopedic PowerPoint Templates.pptxMedical Orthopedic PowerPoint Templates.pptx
Medical Orthopedic PowerPoint Templates.pptx
terusbelajar5
 
The debris of the ‘last major merger’ is dynamically young
The debris of the ‘last major merger’ is dynamically youngThe debris of the ‘last major merger’ is dynamically young
The debris of the ‘last major merger’ is dynamically young
Sérgio Sacani
 
molar-distalization in orthodontics-seminar.pptx
molar-distalization in orthodontics-seminar.pptxmolar-distalization in orthodontics-seminar.pptx
molar-distalization in orthodontics-seminar.pptx
Anagha Prasad
 
Equivariant neural networks and representation theory
Equivariant neural networks and representation theoryEquivariant neural networks and representation theory
Equivariant neural networks and representation theory
Daniel Tubbenhauer
 
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
AbdullaAlAsif1
 
8.Isolation of pure cultures and preservation of cultures.pdf
8.Isolation of pure cultures and preservation of cultures.pdf8.Isolation of pure cultures and preservation of cultures.pdf
8.Isolation of pure cultures and preservation of cultures.pdf
by6843629
 
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills MN
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Ana Luísa Pinho
 
Phenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvementPhenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvement
IshaGoswami9
 
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptxThe use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
MAGOTI ERNEST
 
The binding of cosmological structures by massless topological defects
The binding of cosmological structures by massless topological defectsThe binding of cosmological structures by massless topological defects
The binding of cosmological structures by massless topological defects
Sérgio Sacani
 

Recently uploaded (20)

Shallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptxShallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptx
 
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
 
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
 
Bob Reedy - Nitrate in Texas Groundwater.pdf
Bob Reedy - Nitrate in Texas Groundwater.pdfBob Reedy - Nitrate in Texas Groundwater.pdf
Bob Reedy - Nitrate in Texas Groundwater.pdf
 
Deep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless ReproducibilityDeep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless Reproducibility
 
THEMATIC APPERCEPTION TEST(TAT) cognitive abilities, creativity, and critic...
THEMATIC  APPERCEPTION  TEST(TAT) cognitive abilities, creativity, and critic...THEMATIC  APPERCEPTION  TEST(TAT) cognitive abilities, creativity, and critic...
THEMATIC APPERCEPTION TEST(TAT) cognitive abilities, creativity, and critic...
 
What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
 
Topic: SICKLE CELL DISEASE IN CHILDREN-3.pdf
Topic: SICKLE CELL DISEASE IN CHILDREN-3.pdfTopic: SICKLE CELL DISEASE IN CHILDREN-3.pdf
Topic: SICKLE CELL DISEASE IN CHILDREN-3.pdf
 
SAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdfSAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdf
 
Medical Orthopedic PowerPoint Templates.pptx
Medical Orthopedic PowerPoint Templates.pptxMedical Orthopedic PowerPoint Templates.pptx
Medical Orthopedic PowerPoint Templates.pptx
 
The debris of the ‘last major merger’ is dynamically young
The debris of the ‘last major merger’ is dynamically youngThe debris of the ‘last major merger’ is dynamically young
The debris of the ‘last major merger’ is dynamically young
 
molar-distalization in orthodontics-seminar.pptx
molar-distalization in orthodontics-seminar.pptxmolar-distalization in orthodontics-seminar.pptx
molar-distalization in orthodontics-seminar.pptx
 
Equivariant neural networks and representation theory
Equivariant neural networks and representation theoryEquivariant neural networks and representation theory
Equivariant neural networks and representation theory
 
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
 
8.Isolation of pure cultures and preservation of cultures.pdf
8.Isolation of pure cultures and preservation of cultures.pdf8.Isolation of pure cultures and preservation of cultures.pdf
8.Isolation of pure cultures and preservation of cultures.pdf
 
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
 
Phenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvementPhenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvement
 
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptxThe use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
 
The binding of cosmological structures by massless topological defects
The binding of cosmological structures by massless topological defectsThe binding of cosmological structures by massless topological defects
The binding of cosmological structures by massless topological defects
 

Expressiveness and Model of the Polymorphic λ Calculus

  • 1. Expressiveness and Model of the Polymorphic λ Calculus Shin-Cheng Mu IIS, Sinica Friday, April 11, 14
  • 2. Motivation • V. Vene in APLAS 2004 [GUV04] gave a new proof of shortcut deforestation because it was only proved “informally by theorem-for free.” • But what’s wrong with theorem for free? • So I studied polymorphism and realised that there is a lot I did not know... Friday, April 11, 14
  • 3. Parametricity, or the “theorems for free.” • Informally known by functional programmers as the “theorems for free.” • A polymorphic function’s type induces a “theorem”. • E.g. hd . map f = f . hd, for all hd:: [a]→a, regradless of its actual definition. • The word “theorem” may be mis-leading, however. [Wad89] Friday, April 11, 14
  • 4. In this talk • Review some members of the λ calculus family: • Untyped λ calculus: λx . x • Simply-typed λ calculus: λx:Int . x • Polymorphic λ calculus: Λα.(λx:α . x), Δα.α--->τ, f [a] x • Consider their termination property, expressiveness, and model. Friday, April 11, 14
  • 5. Untyped λ calculus • Not always terminating: (λx.(x x))(λx.(x x)) • Recursion: Y f = (λx . f (x x))(λx . f (x x)) • Equivalent to Turing machine (Church & Kleene). • Denotational model not trivial: requires Scott domains. Friday, April 11, 14
  • 6. Simply-typed λ calculus • Strongly normalisable: all well-typed expression terminates. Y combinator cannot be typed. • Computes total functions only! • Has a simple model of total functions and sets. • Apparently cannot define some useful functions. But exactly how expressive? Friday, April 11, 14
  • 7. The computability hierarchy partial recursive (functions) total recursive primitive recursive elementry recursive Friday, April 11, 14
  • 8. Primitive recursion • A function that can be implemented using only for-loops (math world). It always terminate. • Zero: 0, succ: (1+), projection: (x1,...,xn)= xi. • Composition: f o g. • Primitive recursion: h(0,x) = f(x) h(n+1,x) = g (h(n),n,x) Friday, April 11, 14
  • 9. Primitive recursion • A function that can be implemented using only for-loops (math world). It always terminate. • Zero: 0, succ: (1+), projection: (x1,...,xn)= xi. • Composition: f o g. • Primitive recursion: h(0,x) = f(x) h(n+1,x) = g (h(n),n,x) h(0) = c h(n+1) = g (h(n),n) Familiar? It’s paramorphism! [Mee90] Friday, April 11, 14
  • 10. Partial and total recursion • Partial recursive functions: primitive recursion plus unbounded search: μf z = least x such that f(x,z) = 0. • The search may not terminate, thus introduces the partiality. • Partial rec. fn. is equiv. to Turing machine. • Total recursive functions: the subset of parital rec. fn. that is total. It’s bigger than primitive recursive functions! (eg. Ackermann’s function.) Friday, April 11, 14
  • 11. Elementary recursion • Also called Kalmar elementary functions.  Functions definable by 1, +, x, -., and  SUM f (x,n) = Σn i=0 f(x,i)  PRO f (x,n) = Πn i=0 f(x,i) • Definable functions include: mod, div, isPrime, etc. Friday, April 11, 14
  • 12. Representing natural num. • Rep. of n over domain τ: λf:τ--->τ . λx:τ . f (... (f x)) with n occur. of f. • If we allow different instantiation of τ, we can define addition, multiplication, exp(Ii+1--> Ii---> Ii), predecessor(Ii+3---> Ii)... but not subtraction. • Therefore simply-typed calculus is weaker than elementary functions. Moreover, its value is bound by elementary fns. Friday, April 11, 14
  • 13. • Use the type Δα.(α--->α)--->(α--->α) to represent natural numbers. • addition, multiplication, subtraction,pairs,.. • primrec = Δα.λg:N--->α--->α.λc:α. λn:N.snd(n[Nxα] (λz:Nxα.<1+fst z,g (fst z) (snd z)>) <0,c>) Polymorphism enhances expressiveness Friday, April 11, 14
  • 14. • Use the type Δα.(α--->α)--->(α--->α) to represent natural numbers. • addition, multiplication, subtraction,pairs,.. • primrec = Δα.λg:N--->α--->α.λc:α. λn:N.snd(n[Nxα] (λz:Nxα.<1+fst z,g (fst z) (snd z)>) <0,c>) Polymorphism enhances expressiveness primrec = Δα.λg.λc. λn.snd (n (λz.<1+fst z,g (fst z) (snd z)>) <0,c>) Friday, April 11, 14
  • 15. Ackermann’s function! Define ack without recursion? [Rey85] ack 0 n = n+1 ack (m+1) 0 = ack m 1 ack (m+1) (n+1) = ack m (ack (m+1) n) • Guess: ack = λm. m aug (1+) therefore ack (m+1) = aug (ack m) • ack (m+1) (n+1) = aug (ack m) (n+1) = ack m (aug (ack m) n) = ack m (ack (m+1) n) • We want aug f 0 = f 1 and aug f (n+1) = f (aug f n) • Solution: aug = λf. λn. (n+1) f 1 Friday, April 11, 14
  • 16. Simulating data structures • Let list a = Δβ.(a--->β--->β) ---> β ---> β nil = Λβ.λf.λa.a cons x xs = Λβ.λf.λa. f x (xs f a) • append xs ys = xs cons ys • append = λxs:list a. λys:list a . xs[list a] (λx:a.λzs:list a . cons x zs) ys [Rey85] Friday, April 11, 14
  • 17. Simulating data structures • Let list a = Δβ.(a--->β--->β) ---> β ---> β nil = Λβ.λf.λa.a cons x xs = Λβ.λf.λa. f x (xs f a) • append xs ys = xs cons ys • append = λxs:list a. λys:list a . xs[list a] (λx:a.λzs:list a . cons x zs) ys ! nil = Λβ.λf:a--->β--->β.λa:a.a cons x xs = Λβ.λf:a--->β--->β.λa:a. f x (xs f a) [Rey85] Friday, April 11, 14
  • 18. Where does it stand? partial recursive (functions) total recursive primitive recursive elementry recursive Polymorphic λ Simply-typed λ Friday, April 11, 14
  • 19. Fundamental sequence • Define f0(x) = x+1 • fn+1(x)= fx n(x) = fn(fn...(fn(x))..)... x applications. • f1(x)=2x, f2(x)=2x ×x • fΘ(x)=fΘ[x](x) for limit ordinal Θ. • Limit ordinals: ω is the size of natural numbers, ε0 is the limit of ω, ωω , ωωω ..... Friday, April 11, 14
  • 20. Hierarchy characterised by rate of growth • Running time of elementary functions are bounded by fn 2(x) for some n. • Time of primitive recursive functions are bounded by fn(x) for some n< ω. • Ackermann’s function is essentially fω(x). • fε0(x) is representable in polymorphic λ calculus! • It represents exactly the functions provably recursive in 2nd-order arithmetic -- a much larger class than fε0(x). [FLD83] Friday, April 11, 14
  • 21. Termination • Still, every function defined in poly-λ terminates. • However, the termination cannot be proved in Peano arithmetic! • Peano arithmetic: 0, (1+), addition, induction... covering most techniques we use in proofs of programs. • Godel’s incompleteness theorem stated that there are true theorems not provable in PA. This was the first “interesting” example. [FLD83] Friday, April 11, 14
  • 22. Model for poly. λ calculus? • Untyped λ: not terminating, needs domain. • Simple-typed λ: terminating, set-theoretic. • λx:Int.x is the id for Int, λx:Char.x for Char. • Poly. λ: can we avoid using domains? • First try: a polymorphic function is a collection of functions indexed by type. • Λα.λx:α.x is a collection of identity fns. • However, that would include some ad-hoc functions. Friday, April 11, 14
  • 23. Parametricity • Reynolds restricts polymorphic objects to parametric values: • Let p: Δα.τ. It is parametric if for all set assignments s1, s2, and r s1×s2: 〈p s1, p s2〉 [id|α:r]# τ • Which later became “theorem for free”. • Reynolds [Rey83] believed that there is a set- theoretic model for poly. λ where poly. objects represent parametric values. • He then falsified his conjecture [Rey84]. [Wad89] Friday, April 11, 14
  • 24. No simple model! • Bool can be represented by B=Δα.α--->α--->α • Let Ts = (s--->B)--->B for all type s, and Tf = λh.λg.h(g o f) (for all f: s--->t, Tf: Ts--->Tt). • Let P=(((s--->B)--->B)--->s)--->s. We can construct a h: TP--->P s.t. the diagram commutes for all f. • In fact h is an initial algebra! • But that would make TP isomorphic to P, which is a contradiction (they have diff. cardinalities unless |B|=1). h P TP s Ts Tgg f [Rey84]Polymor phism is not set-theoretic. f. g. Friday, April 11, 14
  • 25. Later models • Using topos [Pit87]Poly. is set-theoretic, constructively. • Frame [BM84][MM85][Wad89]. • Functorial approach [BFS90]. • Operational aspects [Pit00]. • Used to prove short-cut fusion [Joh03]. Friday, April 11, 14
  • 26. What’s the use of parametricity? • It’s still a key concept! Recall representation of lists: llist a = Δβ.(a--->β--->β) ---> β ---> β. • In general, the least fixed-point of functor F (or the inital F-algebra) can be represented by Δβ.(F β--->β) ---> β... iff parametricity holds! • Types defined as least-fixed-points are called inductive. • nil = Λβ.λf.λa.a, cons x xs = Λβ.λf.λa. f x (xs f a), x = cons 1 (cons 2 (cons 3 nil). [Has94] Friday, April 11, 14
  • 27. Inductive and coinductive datatypes • The greatest fixed-point of functor F can be represented by ∃x.(x → F x, x), iff parametricity holds. It’s called coinductive. • from n = (λm.Right (m,m+1), n) :: glist a • When least and greatest fixed-points coincide (i.e. exists a force:: glist a →llist a), we can do hylomorphism. [Has94] [How96] Friday, April 11, 14
  • 28. Pointed types • In a model where parametricity and extensionality holds, the following are equivalent: • Inductive and coinductive types coincide; • Exists a fixed-point operator for values; • Exists a fixed-point operator for types. [Has94] ? Friday, April 11, 14
  • 29. Conclusion Termination Expressiveness Model Untyped NO = Turing machine domain Simply typed YES < elementry fn. set & functio n Polymorphic YES but not provable in PA > Ackermann domain or non-trivial sets Friday, April 11, 14
  • 30. What I learnt from this history study... • Adding polymorphism to a language strongly enhances its power. • The concept of fold, etc., finds its root in very fundamental research. • Category theory has played an important role in early stage of computing science. • Parametricity is an important assumption leading to many useful properties. Friday, April 11, 14
  • 31. References • [FLD83] S.Fortune, D. Leivant, M. O’Donnell, The expressiveness of simple and second-order type structures. In Journal of the ACM, 30(1), pp 151-185. • [Rey83] J.C. Reynolds. Types, abstractions and parametric polymorphism. In Information Processing 83, pp 513-523. • [BM84]K.B. Bruce, A.R. Meyer, The semantics of second-order polymorphic lambda calculus. In Semantics of Data Types, LNCS 173. • [Rey84] J.C. Reynolds, Polymorphism is not set theoretic. In Semantics of data Types, LNCS 173, pp 145-156. • [MM85] J.C. Mitchell, A.R. Meyer, Second-order logical relations. In Logics of Programs, LNCS 193. • [Rey85] J.C. Reynolds, Three approaches to type structure. In Mathematical Foundations of Software Development, LNCS 185. Friday, April 11, 14
  • 32. References • [Pit87] A.M. Pitts, Polymorphism is set theoretic, constructively. In Category Theory and Computer Science, LNCS 283, pp 12-39. • [Wad89] P. Wadler, Theorems for free! In Int. Sym. on Functional Programming Languages and Computer Architecture, ‘89. • [BFS90] E.S. Bainbridge, P.J. Freyd, A. Scedrov, P.J. Scott, Functorial polymorphism. In Theoretical computer science v.70, pp 36-54. • [Mee90] L. Meertens, Paramorphisms. In Formal Aspects of Computing. • [Has94] R. Hasegawa. Categorical data types in parametric polymorphism. Math. Structures in Computer Science, March 1994. • [How96] B.T. Howard. Inductive, coinductive, and pointed types. ICFP 96. • [Pit00] A.M. Pitts, Parametric polymorphism and operational equivalence. In Math. Struct. in Comp. Science v.10, pp 1-39. • [Joh03] P. Johann, Short cut fusion is correct. In J. Functional Programming v.13, pp 797-814. • [GUV04]N. Ghani, T. Uustalu, V, Vene, Build, augment and destory. In APLAS 2004, LNCS 3002, pp 327-347. Friday, April 11, 14