Composition

Gleanings from

the Essence of Simplicity

&

Category Theory

Lambda Calculus

Whose definition of simple?

Mathematics

Abstractions without Leaks

Simplicity as Atomicity

Bit = 0 | 1

Software

is Not Atomic

Bad Combinations

Occam's Razor for Code?

versus

More Things <> Complex

Divide! (Carefully)

Inductive Simplicity

Simple (atomic) things

Put together in simple ways

?

Composition: Categories

The essence of a category is composition. Or, if you prefer, the essence of composition is a category.

—Bartosz Milewski

https://bartoszmilewski.com/2014/11/04/
category-the-essence-of-composition/

What is a Category?

A category is an embarrassingly simple concept. A category consists of objects and arrows that go between them.

—Bartosz Milewski

https://bartoszmilewski.com/2014/11/04/
category-the-essence-of-composition/

Two Laws of a Category

1. Associativity of morphisms

https://bartoszmilewski.com/2014/11/04/
category-the-essence-of-composition/

2. Existence of an Identity morphism

Categorical Simplicity

HATEOS

Algebraic Data Types

Generics

Libraries vs Frameworks

Unix Philosophy

HATEOS

Algebraic Data Types

Generics

Libraries vs Frameworks

Unix Philosophy

Simple: Lambda Calculus

<expr> ::= <name> | <func> | <appl>

<name> is an identifier (sorry, no BNF)

<func> ::= λ<name>.<body>

<body> ::= <expr>

<appl> ::= (<func> <expr>)

Lambda Examples

λx.x

λf.λa.(f a)

λx.λy.x

λf.λx.λy.(f y x)

Lambda Limits Options

Exactly one argument

Exactly one return value

Pure expressions

λx.x

λx.x

Compose Functions

λfλgλx.(f (g x))

Is this composible?

Code that composes

Compiler composition

https://github.com/CraigStuntz/TinyLanguage

module Compiler

let compile =
    Lexer.lex
    >> Parser.parse
    >> Binder.bind
    >> OptimizeBinding.optimize
    >> IlGenerator.codegen
    >> Railway.map OptimizeIl.optimize
    >> Railway.map Il.toAssemblyBuilder

2D Inductive Composition

Compose atomic entities and then lift the resultant entity to the next level of abstraction as an atomic entity, and repeat

For Further Reference

https://bartoszmilewski.com/2014/10/28
/category-theory-for-programmers-the-preface/

Compose atomic entities

Composition, the Essence of Simplicity: Gleanings from Category Theory and Lambda Calculus

By Keith Pinson

Composition, the Essence of Simplicity: Gleanings from Category Theory and Lambda Calculus

For Pittsburgh Functional Programming

  • 1,264