From Curry to Haskell Syntactical insights at the confluence of , algebra and programming

Felice Cardone

Dipartimento di Informatica Universit`adi Torino

16 March 2016

Felice Cardone From Curry to Haskell Curry’s achievements

Curry’s timeline 1927 Invention of combinators (I, W, B, C) 1930 PhD in G¨ottingenunder Hilbert, birth of combinatory logic 1934 Theory of functionality; “propositions as types” 1939 Outlines of a Formalist Philosophy of Mathematics 1942 Curry’s paradox 1950 Theory of formal deducibility 1958 (with R. Feys) Combinatory Logic I Haskell Brooks Curry (1920) 1972 (with J. R. Hindley and J. P. Seldin) Combinatory Logic II

Felice Cardone From Curry to Haskell Overview

Curry’s contribution to is mostly identified with outcomes of the theory of combinators

I the lazy functional Haskell

I implementation of functional programming languages via combinator reduction machines

I types and the propositions as types analogy

In this talk I focus on neglected aspects of Curry’s work: formal systems and syntactic structure and their influence on programming

Felice Cardone From Curry to Haskell Plan

Theory of meaning Dialogue games Formal systems

Constructions Semiotics Lorenzen Abstract syntax Calculi Inversion principle

Curry Admissible rules

Haskell Structural induction

Free structures McCarthy Burstall Landin Programming

Felice Cardone From Curry to Haskell Plan

Theory of meaning Dialogue games Formal systems

Constructions Semiotics Lorenzen Abstract syntax Calculi Inversion principle

Curry Admissible rules

Haskell Structural induction

Free structures McCarthy Burstall Landin Programming

Felice Cardone From Curry to Haskell Formal systems

Felice Cardone From Curry to Haskell Formal systems: example [Curry, 1949]

We start from the alphabet with three symbols {a, b, c}. The expressions are the finite sequences of symbols. We single out classes of expressions by means of rules:

I Sams: X sam a sam Xb sam

I Tettles: X sam Y sam XcY tettle

I Tantets: XcY tantet aca tantet XbcYb tantet

Felice Cardone From Curry to Haskell Special types of formal systems

A basic kind of formal system is built from:

I Obs, formed from a set Ω of operations and atoms. Obs constructed by different processes are distinct.

I Elementary statements, formed by applying predicates (of degree n) to n obs.

I Axioms, which are statements, and rules for inferring statement from other statements.

Felice Cardone From Curry to Haskell Sams, tettles and tantets as an ob system

I Sams: X is a sam 0 is a sam σ(X ) is a sam

I Tettles: X is a sam Y is a sam X = Y is a tettle

I Tantets: X = Y is a tantet 0 = 0 is a tantet σ(X ) = σ(Y ) is a tantet

Felice Cardone From Curry to Haskell The semiotics of formal systems

I A formal system is an activity carried out in the language being used for communication (U-language), which is extended by nouns and verbs used for denoting obs and sentences (the A-language).

I The construction of a formal system is an elaborate semiotic process: Curry described in detail the linguistic aspects of formal systems. Example: the theory of grammatical categories, based on the theory of functionality from combinatory logic.

I The semiotic parts of Curry and Feys (1958) – together with Carnap’s Introduction to Semantics (1948) – influenced the linguistic approach to programming language theory, in particular Saul Gorn.

Felice Cardone From Curry to Haskell Example: an ob

the holes are for the attachment of strings from the constituents A, B while the rings are for attachment of a string connecting to an operation when the A ◦ B or A0 is itself a constituent of a more complex term (Curry, 1941)

Felice Cardone From Curry to Haskell Example: an ob

Alexander Calder, Mobile (c. 1932) Tate Modern, London

Felice Cardone From Curry to Haskell Example: a formal system

Computations as proofs in structured operational semantics (Plotkin, 1981)

I Obs: built from atoms >, ⊥ by an operation ∨ of degree 2

I Elementary statements: X ; Y for obs X , Y

I Axioms and rules:

> ; > ⊥ ; ⊥ X ; > X ; ⊥ Y ; Z X ∨ Y ; > X ∨ Y ; Z

Felice Cardone From Curry to Haskell Example: a formal system

Computations as proofs in structured operational semantics (Plotkin, 1981)

I Obs: built from atoms >, ⊥ by an operation ∨ of degree 2

I Elementary statements: X ; Y for obs X , Y

I Axioms and rules:

> ; > ⊥ ; ⊥ X ; > X ; ⊥ Y ; Z X ∨ Y ; > X ∨ Y ; Z

Felice Cardone From Curry to Haskell > ; > ⊥ ; ⊥ > ∨ ⊥ ; >

⊥ ; ⊥ ⊥ ; ⊥ ⊥ ∨ ⊥ ; ⊥ ⊥ ∨ (> ∨ ⊥) ; >

Sample computation

(⊥ ∨ ⊥) ∨ (⊥ ∨ (> ∨ ⊥)) ; >

Felice Cardone From Curry to Haskell > ; > ⊥ ; ⊥ ⊥ ; ⊥ ⊥ ; ⊥ > ∨ ⊥ ; > ⊥ ∨ (> ∨ ⊥) ; >

Sample computation

⊥ ∨ ⊥ ; ⊥ (⊥ ∨ ⊥) ∨ (⊥ ∨ (> ∨ ⊥)) ; >

Felice Cardone From Curry to Haskell > ; > ⊥ ; ⊥ ⊥ ; ⊥ > ∨ ⊥ ; > ⊥ ∨ (> ∨ ⊥) ; >

Sample computation

⊥ ; ⊥ ⊥ ∨ ⊥ ; ⊥ (⊥ ∨ ⊥) ∨ (⊥ ∨ (> ∨ ⊥)) ; >

Felice Cardone From Curry to Haskell > ; > ⊥ ; ⊥ > ∨ ⊥ ; > ⊥ ∨ (> ∨ ⊥) ; >

Sample computation

⊥ ; ⊥ ⊥ ; ⊥ ⊥ ∨ ⊥ ; ⊥ (⊥ ∨ ⊥) ∨ (⊥ ∨ (> ∨ ⊥)) ; >

Felice Cardone From Curry to Haskell > ; > ⊥ ; ⊥ > ∨ ⊥ ; >

Sample computation

⊥ ; ⊥ ⊥ ; ⊥ ⊥ ∨ ⊥ ; ⊥ ⊥ ∨ (> ∨ ⊥) ; > (⊥ ∨ ⊥) ∨ (⊥ ∨ (> ∨ ⊥)) ; >

Felice Cardone From Curry to Haskell > ; > > ∨ ⊥ ; >

Sample computation

⊥ ; ⊥ ⊥ ; ⊥ ⊥ ; ⊥ ⊥ ∨ ⊥ ; ⊥ ⊥ ∨ (> ∨ ⊥) ; > (⊥ ∨ ⊥) ∨ (⊥ ∨ (> ∨ ⊥)) ; >

Felice Cardone From Curry to Haskell > ; >

Sample computation

⊥ ; ⊥ ⊥ ; ⊥ ⊥ ; ⊥ > ∨ ⊥ ; > ⊥ ∨ ⊥ ; ⊥ ⊥ ∨ (> ∨ ⊥) ; > (⊥ ∨ ⊥) ∨ (⊥ ∨ (> ∨ ⊥)) ; >

Felice Cardone From Curry to Haskell Sample computation

> ; > ⊥ ; ⊥ ⊥ ; ⊥ ⊥ ; ⊥ > ∨ ⊥ ; > ⊥ ∨ ⊥ ; ⊥ ⊥ ∨ (> ∨ ⊥) ; > (⊥ ∨ ⊥) ∨ (⊥ ∨ (> ∨ ⊥)) ; >

Felice Cardone From Curry to Haskell Variations on a theme of Curry

Felice Cardone From Curry to Haskell Obs and their formation

In an ob system, an operation ω (of degree n) forms an ob b from n obs a1,..., an, denoted by

ω(a1,..., an)

the genesis of such a b from ω, a1,..., an will also be referred to as a formation (of b), and for this formation ω will be called the operation, a1,..., an the arguments, and b the closure (Curry, 1952)

Felice Cardone From Curry to Haskell An aside: why is this interesting?

I Distinction between act and product (Twardowski, Actions and Products, 1912)

I Examples: construction, judgement, proof, organization,. . .

I The distinction has been refined for judgements by Sundholm and Martin-L¨ofto that between act, product, and content. For certain kinds of acts (e.g., proof) we also have their trace.

I These distinctions are useful for a full understanding of the constructive explanations of the logical constants.

Felice Cardone From Curry to Haskell The anatomy of an ob

We distinguish:

I the formation of the ob b = ω(a1,..., an)(act), denoted by

hω · a1,..., ani

I the closure of a formation ξ (product) denoted by ξ. Therefore ω(a1,..., an) ≡ hω · a1,..., ani

Felice Cardone From Curry to Haskell The anatomy of an ob

We introduce “types”:

I Ω(X ) is the type of obs built from elements of X using operations in Ω

I Ω is the type of operations I Ω(X ) is the type of formations with arguments in X with rules (simplified)

ω :Ω a : Ω(X ) ξ : Ω(Ω(X )) hω · ai : Ω(Ω(X )) ξ : Ω(X )

Then, for example:

ω :Ω a : Ω(X ) hω · ai : Ω(Ω(X )) ω(a) ≡ hω · ai : Ω(X )

Felice Cardone From Curry to Haskell The standard algebraic approach

I Ω(X ) is the set of terms (= trees) over “variables” X and operations Ω - I There is a natural coercion ηX : X Ω(X ) mapping each x ∈ X to a one-node tree hxi

I There is a natural composition as substitution of trees

- µX : Ω(Ω(X )) Ω(X )

I Ω(·): Set - Set is a monad

Felice Cardone From Curry to Haskell Composition as substitution

Here x, y ∈ Ω({v, w}), a ∈ Ω({x, y}):

a

x x

y y

v v w

Felice Cardone From Curry to Haskell Composition as substitution

Here x, y ∈ Ω({v, w}), a ∈ Ω({x, y}):

a

x x

y y

v v w

a

Then µ{v,w}(a) ∈ Ω({v, w})

v v w

Felice Cardone From Curry to Haskell The standard algebraic approach — Take 2

I Given a signature Ω and f : X - Y , define Ω(X ) = {hω · ai | ω ∈ Ω, a ∈ X } Ω(f )(hω · ai) = hω · f (a)i

I An Ω-algebra is a set A with a mapping

δ : Ω(A) - A

0 I An Ω-homomorphism is a mapping h : A - A such that

δ Ω(A) - A

Ω(h) h

? ? δ0 Ω(A0) - A0

Felice Cardone From Curry to Haskell The standard algebraic approach — Take 2

- Then Ω(X ) becomes an Ω-algebra τX : Ω(Ω(X )) Ω(X ) where

τX (hω · ai) = hω · ai = ω(a)

I Ω(X ) is the free Ω-algebra over X

I Ω(·) is the free monad generated by Ω

Felice Cardone From Curry to Haskell I Lorenzen Calculi (Einf¨uhrungin die Operative Logik und Mathematik, 1955) with rules of the form:

A1 ... An A

(originally written as

A1,..., An → A)

where Ai , A are strings of atomic figures from a finite alphabet and variables

Variants of formal systems

I Post Canonical and normal systems (1920s) as a model of the process of generation of sets of “theorems” formal grammar (Harris and Chomsky, early 1950s)

Felice Cardone From Curry to Haskell Variants of formal systems

I Post Canonical and normal systems (1920s) as a model of the process of generation of sets of “theorems” formal grammar (Harris and Chomsky, early 1950s)

I Lorenzen Calculi (Einf¨uhrungin die Operative Logik und Mathematik, 1955) with rules of the form:

A1 ... An A

(originally written as

A1,..., An → A)

where Ai , A are strings of atomic figures from a finite alphabet and variables

Felice Cardone From Curry to Haskell Calculi: an example

I Atomic figures: +, o

I Variables: X

I Rules( R1) X → Xo,(R2) X → +X +

A derivation: + +o +oo + + oo+ + + oo + o

Felice Cardone From Curry to Haskell Theory of meaning

Felice Cardone From Curry to Haskell Dialogue games

Lorenzen

Inversion principle

Admissible rules

Felice Cardone From Curry to Haskell Admissible rules

I Atomic figures: +, o

I Variables: X

I Rules( R1) X → Xo,(R2) X → +X +

Admissibility A rule R is admissible relative to a calculus K if any derivation obtained by the use of R can be constructively transformed into one obtained without such use (this definition of admissibility is due to Curry!)

Felice Cardone From Curry to Haskell Admissible rules

I Atomic figures: +, o

I Variables: X

I Rules( R1) X → Xo,(R2) X → +X +

The rule X → ++X is admissible: how could X have been derived? For example . . X 0 . . . . 0 + + X 0 X (R1) (R1) X 0o is transformed into + + X 0o |{z} |{z} X X

Felice Cardone From Curry to Haskell Admissibility and the meaning of logical constants

Assume that A1,..., An, B are elementary statements of a formal system: Curry

A1 ∧ ... ∧ An → B is true just when there is an effective process for obtaining a proof that B holds from a proof that A1,..., An hold. In particular, this holds when B is formally deducible from A1,..., An: A1,..., An ` B

Lorenzen

A conditional formula A1 ∧ ... ∧ An → B is true iff

A1 ∧ ... ∧ An B

is an admissible rule

Felice Cardone From Curry to Haskell Inversion principle

Inversion principle If, in a calculus K, A can only be introduced by the rules

Γ1 Γn A A

then A → C is admissible relative to K when

Γ1 Γn C C

are used as additional rules

Felice Cardone From Curry to Haskell Elimination rules follow from introduction rules (Gentzen)

Justification of the inversion principle

Assume that A can only be introduced by means of the “introduction” rules Γ1 Γn A A If A is a theorem of K, then A must have been obtained using some rule Γi A

because every element of Γi has been derived. Then we can derive C by means of the rule Γi C

Felice Cardone From Curry to Haskell Justification of the inversion principle

Assume that A can only be introduced by means of the “introduction” rules Γ1 Γn A A If A is a theorem of K, then A must have been obtained using some rule Γi A

because every element of Γi has been derived. Then we can derive C by means of the rule Γi C Elimination rules follow from introduction rules (Gentzen)

Felice Cardone From Curry to Haskell x ∈ A . . f (x) ∈ A A

A general inversion principle: free structures

Natural numbers N Under the “propositions as types” correspondence, read

n ∈ N as n is a proof of N

There are two introduction rules for N n ∈ N 0 ∈ N σ(n) ∈ N

When an “elimination rule” N → A is admissible? Assume we have proofs a ∈ A, f : A - A and n ∈ N

n = 0 ∈ N a ∈ A n ∈ N a ∈ A

Felice Cardone From Curry to Haskell A

A general inversion principle: free structures

Natural numbers N Under the “propositions as types” correspondence, read

n ∈ N as n is a proof of N

There are two introduction rules for N n ∈ N 0 ∈ N σ(n) ∈ N

When an “elimination rule” N → A is admissible? Assume we have proofs a ∈ A, f : A - A and n ∈ N

x ∈ N x˜ ∈. A . . . . n = σ(x) ∈ N f (˜x) ∈ A n ∈ N f (˜x) ∈ A

Felice Cardone From Curry to Haskell A general inversion principle: free structures

Natural numbers N Under the “propositions as types” correspondence, read

n ∈ N as n is a proof of N

There are two introduction rules for N n ∈ N 0 ∈ N σ(n) ∈ N

When an “elimination rule” N → A is admissible? Assume we have proofs a ∈ A, f : A - A and n ∈ N

x˜ ∈ A . . a ∈ A f (˜x) ∈ An ∈ N it(a, f , n) ∈ A

Felice Cardone From Curry to Haskell Computation rule

Iteration for natural numbers For a ∈ A, f : A - A:

it(a, f , 0) = a it(a, f , σ(n)) = f (it(a, f , n)) Cfr. Definition by recursion (Dedekind, 1888)

For any ha ∈ A, f : A - Ai there is one mapping

it(a, f ): N - A

such that

it(a, f )(0) = b it(a, f )(σ(n)) = f (it(a, f )(n))

Felice Cardone From Curry to Haskell A general inversion principle: free structures

Lists of A a ∈ A ` ∈ List(A) Nil ∈ List(A) Cons(a, `) ∈ List(A) Similarly we have

a ∈ A ` ∈ List(A) . . a ∈ A f (a, `) ∈ A x ∈ List(A) lit(a, f , x) ∈ A with computation rule

lit(a, f , Nil) = a lit(a, f , Cons(a, `)) = f (a, lit(a, f , `))

Felice Cardone From Curry to Haskell Programming

Felice Cardone From Curry to Haskell Haskell Structural induction

Free structures McCarthy Burstall Landin Programming

Felice Cardone From Curry to Haskell It happended in 1969

Felice Cardone From Curry to Haskell It happended in 1969

Felice Cardone From Curry to Haskell It happended in 1969

Felice Cardone From Curry to Haskell It happended in 1969

For example, to prove that all lists have a certain property we show that a list has the property provided that all its sublists have the property, and in particular that the null list (which has no sublists) has the property. This is the induction principle used by McCarthy and Painter (1966). Curry and Feys (1958) call it ‘structural induction’.

Curry and Feys Volume One was another of the bibles that was read (Landin, 2002)

Felice Cardone From Curry to Haskell Structural induction and programming: from Burstall . . .

Felice Cardone From Curry to Haskell . . . to Haskell

Felice Cardone From Curry to Haskell Abstract syntax (McCarthy, 1962)

I The Backus normal form that is used in the ALGOL report, describes the morphology of ALGOL programs in a synthetic manner. Namely, it describes how the various kinds of programs are built up from their parts. [Abstract syntax] is analytic rather than synthetic; it tells how to take a program apart, rather than how to put it together.

I Second, [abstract syntax] is abstract in that it is independent of the notation used to represent, say sums, but only affirms that they can be recognized and taken apart.

Felice Cardone From Curry to Haskell I There is an iterative algorithm for parsing obs written in postfix polish notation (Menger, 1930; Schr¨oter,1943; Gerneth, 1948; Hall, c. 1950; Rosenbloom, 1950): 1. let the rank of an atom be 1, the rank of an operation of degree n be −n + 1. 2. scan from left to right the sequence of symbols adding their ranks: if the partial sums are never negative and final sum is 1, the sequence represents an ob I There is an algorithm for evaluating an ob represented in postfix polish (Bauer and Samelson; Burks, Warren and Wright, 1954)

The revenge of concrete syntax

How to prove the existence of initial algebras? Some well-known facts: I The elements of Ω(X ) admit a linear representation without parentheses (Lukasiewicz, 1929), in particular one in which every operation symbol follows its arguments (postfix polish notation)

Felice Cardone From Curry to Haskell I There is an algorithm for evaluating an ob represented in postfix polish (Bauer and Samelson; Burks, Warren and Wright, 1954)

The revenge of concrete syntax

How to prove the existence of initial algebras? Some well-known facts: I The elements of Ω(X ) admit a linear representation without parentheses (Lukasiewicz, 1929), in particular one in which every operation symbol follows its arguments (postfix polish notation) I There is an iterative algorithm for parsing obs written in postfix polish notation (Menger, 1930; Schr¨oter,1943; Gerneth, 1948; Hall, c. 1950; Rosenbloom, 1950): 1. let the rank of an atom be 1, the rank of an operation of degree n be −n + 1. 2. scan from left to right the sequence of symbols adding their ranks: if the partial sums are never negative and final sum is 1, the sequence represents an ob

Felice Cardone From Curry to Haskell The revenge of concrete syntax

How to prove the existence of initial algebras? Some well-known facts: I The elements of Ω(X ) admit a linear representation without parentheses (Lukasiewicz, 1929), in particular one in which every operation symbol follows its arguments (postfix polish notation) I There is an iterative algorithm for parsing obs written in postfix polish notation (Menger, 1930; Schr¨oter,1943; Gerneth, 1948; Hall, c. 1950; Rosenbloom, 1950): 1. let the rank of an atom be 1, the rank of an operation of degree n be −n + 1. 2. scan from left to right the sequence of symbols adding their ranks: if the partial sums are never negative and final sum is 1, the sequence represents an ob I There is an algorithm for evaluating an ob represented in postfix polish (Bauer and Samelson; Burks, Warren and Wright, 1954)

Felice Cardone From Curry to Haskell The revenge of concrete syntax

Less well-known fact: ∗ • Let WΩ(X ) ⊆ (Ω ∪ X ) be the Ω-algebra generated by X • Let δ : Ω(Y ) - Y be any Ω-algebra - ∴ for any f : X Y there is a unique Ω-homomorphism

- [[·[]f : WΩ(X ) Y

(Cohn, 1965, after Philip Hall)

Felice Cardone From Curry to Haskell Conclusions

Felice Cardone From Curry to Haskell I The inversion principle for free types needs further investigation. This is a neglected chapter of the “propositions as types” correspondence.

Along similar lines, we may attempt reconstruction of old theorems by new technical means (a small research program)

What next?

I I have suggested an experiment in the formalization of a passage from Curry by “modern” algebraic notions.

Felice Cardone From Curry to Haskell This is a neglected chapter of the “propositions as types” correspondence.

What next?

I I have suggested an experiment in the formalization of a passage from Curry by “modern” algebraic notions. Along similar lines, we may attempt reconstruction of old theorems by new technical means (a small research program)

I The inversion principle for free types needs further investigation.

Felice Cardone From Curry to Haskell What next?

I I have suggested an experiment in the formalization of a passage from Curry by “modern” algebraic notions. Along similar lines, we may attempt reconstruction of old theorems by new technical means (a small research program)

I The inversion principle for free types needs further investigation. This is a neglected chapter of the “propositions as types” correspondence.

Felice Cardone From Curry to Haskell Barry Godber (1946–1970), artist and computer programmer

Thank you!

Felice Cardone From Curry to Haskell Thank you!

Barry Godber (1946–1970), artist and computer programmer

Felice Cardone From Curry to Haskell