Applied Combinators In Application

2023 James B. Wilson, Colorado State University

Think once, Reprogram everywhereTM

Or start a the beginning with "What is a function?"

First Checkout Primitive Functions

Academic Programmer's Quandry

Where to start?

What to make first?

Any "real-world" problem?

How to reuse what exists?

Can I publish a paper?

Is it "real-world" experience?

Is it math?

Can I teach it to a student?

Will my advisor understand?

Where's a proof?

How to finish it?

Will a math system take it?

FACT (Grace Hopper).

Programming is Math.

Programming Idioms: logic written to simulate human language*

Public Domain, original copyright (c) James S. Davis

for x in [1..5] ...

Programming "Idioma" Language 

Collection of idioms that can

model a symbolic logic.

\[\forall x.(1\leq x\leq 5\Rightarrow ...)\]

becomes

*Catch: Math/Logic is human language so much of programming still looks like math/logic.

Advice:

Start with idioms for combinators, but use EVERY language

Combinators

Atomic functions 

  • names, e.g. \(\mathbb{S}\), \(\mathbb{K}\), \(\mathbb{I}\), but also , \(\mathbb{C}\), \(\mathbb{D}\), \(\mathbb{Y}\)...
  • individually basic reductions
  • combined have full computational power

 

Combinatorial Logic = Assembly Language,

 

...but lets skip assembly.

Pure Combinators

Informally

  • \(\mathbf{I}(x)=x\)
  • \(\mathbf{K}_c(x)=c\)
  • \(\mathbf{S}_{f,g}(x)=f(x,g(x))\)

Pure

Combinators

Logically

  • \(\mathbf{I}U\rhd U\)
  • \(\mathbf{K}UV\rhd U\)
  • \(\mathbf{S}UVW\rhd UW(VW)\)

Identity \(\mathbb{I}\)

Untyped Reduction Rule \(\mathbb{I}X\rhd X\)

Example

\[\mathbb{I}7 \rhd 7\qquad \mathbb{I}(27)\rhd 27\]

Untyped Procedural Programing Idiom (Python)

def id(x) :
    return x
let id x = x

Untyped Functional Programing Idiom (OCaml)

Identity \(\mathbb{I}\)

Typed Rules

Typed Procedural Programing Idiom (Java)

X id(X x) {
    return x
}
id:X -> X 
id x = x

Typed Functional Programing Idiom (Haskell/Idris)

\[\frac{X:Type}{\mathbb{I}^X:X\to X}(I)\qquad\begin{array}{l}X:Type\\ x:X\\ \hline \mathbb{I}^X(x):=x \end{array}(C)\]

Konstant \(\mathbb{K}\)

Untyped Reduction Rule \(\mathbb{K}XY\rhd X\)

Example

\[\mathbb{K}27 \rhd 2\qquad \mathbb{K}(27)(13)\rhd 27\]

Untyped Procedural Programing Idiom (Python)

def konst(c,x) :
    return c
let konst c x = c

Untyped Functional Programing Idiom (OCaml)

Typed Rules

Typed Procedural Programing Idiom (Java)

C konst(C c, X x) {
    return c
}
konst:C -> X -> C
konst c = x -> c

Typed Functional Programing Idiom (Haskell/Idris)

Konstant \(\mathbb{K}\)

\[\begin{array}{l} C,X:Type\\ c:X\\ \hline \mathbb{K}_c^{C,X}:X\to C \end{array}(I) \qquad \begin{array}{l} C,X:Type\\ c:C\\ x:X\\ \hline \mathbb{K}_c(x):=c \end{array}(C) \]

Fixed Point \(\mathbb{Y}\)

Untyped Reduction Rule \(\mathbb{Y}X\rhd X(\mathbb{Y}X)\)

Example

\[\mathbb{K}27 \rhd 2\qquad \mathbb{K}(27)(13)\rhd 27\]

Untyped Procedural Programing Idiom (Python)

def konst(c,x) :
    return c
let konst c x = c

Untyped Functional Programing Idiom (OCaml)

Applied Combiantors: Intro to Programming Idioms

By James Wilson

Applied Combiantors: Intro to Programming Idioms

Many functions we use are built from simpler functions and that explains all the qualities of functions: predictable outputs for example. So where does this process get started? What are primitive functions?

  • 193