• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language Coq
  • Created over 9 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Proof of the Pipes Laws

This is a formalization in Coq of the Haskell pipes library. Nearly all its functions have been implemented, and the laws mentioned in the documentation proven. It relies on the coq-haskell project, whose aim is to simplify both the transcoding of Haskell types and functions into Coq, and the extraction of proven algorithms back into Haskell.

Much gratitude is given to Gabriel Gonzalez for dialoging with me about this project over the long months of its inception, and for his manual proofs of the laws, which were an excellent reference. Thanks are also due to Paolo Capriotti and Dan Burton, with whom I never interacted, but who where the spiritual fathers of this formalization effort.

Laws proven

43 laws were proven, with 7 requiring a compromise documented below. These are indicated with bolded leaders in the following list (all of those are proofs involving either of the functions push or pull).

Klesli category

Respond category

Request category

Push category

Pull category

Duals

  • Theorem request_id : reflect \o request = respond
  • Theorem reflect_distrib : reflect (f x >>= g) = reflect (f x) >>= (reflect \o g)
  • Theorem request_comp : reflect \o (f \>\ g) = (reflect \o g) />/ (reflect \o f)
  • Theorem respond_id : reflect \o respond = request
  • Theorem respond_comp : reflect \o (f />/ g) = (reflect \o g) \>\ (reflect \o f)
  • Corollary distributivity : reflect \o (f >=> g) = (reflect \o f) >=> (reflect \o g)
  • Theorem zero_law : reflect \o pure = pure
  • Theorem involution : reflect \o reflect = id

General theorems

Prelude functions

The Compromise

push and pull are necessarily infinite functions. However, representing them as co-fixpoints makes some other things impossible (for example, runEffect must be a fixpoint). So rather than splitting up the development, a balance was struck. This compromise is three-fold:

  1. push and pull are implemented in terms of "fuel". When fuel is exhausted, they return Pure someDefault.

  2. An axiom is added such that there is always fuel (i.e., fuel > 0).

  3. A second axiom is added to assert that a "step" of push or pull at fuel N behaves identically to that at fuel N+1. (i.e., forall n, n > 0 -> push (fuel:=n) = push (fuel:=n.+1))

This allows push and pull to be defined inductively, but used in a context where the "base case" cannot be reached, making them infinite for the purposes of proof.

History of this work

2013 Oct 6, Gabriel made his hand-written proofs of the pipes laws public. Dan Burton commented that someone should mechanize them in Agda. Gabriel mentioned he had started down that road already, with help from Paolo Capriotti.

2013 Oct 7, I also began trying to encode the laws in Agda, so Gabriel and I began discussing the problems of strict positivity regarding the Proxy type.

2014 Nov 16, after letting the project lie for a while, I started playing around with teasing Proxy into a functor ProxyF under the free monad. Gabriel tells me this is exactly what pipes 2.4.0 did, so with that confirmation I started down the road of how to encode free monads in Coq. I made the switch to Coq after being inspired by talks at OPLSS 2014, and because I was using it for a large project at work.

Over the next few months I read several papers by Conor McBride suggesting the use of container types, even formalizing most of his paper Kleisli Arrows of Outrageous Fortune. This, plus comments made by Paolo Capriotti, gave me much food for thought, although little code was written.

Around 2015 Mar 1 I read an old paper by Venanzio Capretta on Universal Algebra in Type Theory which made container types far more comprehensible to me, thus energizing me to consider this project again.

2015 May 30, After a few weeks of trying various free monad encodings based on container types and universal algebra, I stumbled across a trick Edward Kmett used for his Boehm-Berarducci encoding of the free monad transformer. It turns out that although he did this to improve GHC roles for an applied functor, it also solves the strict positivity issue in Coq!

2015 May 31, With this trick in hand, I was able to transcode most of the pipes library directly from Haskell, requiring only minor syntactic variations to adapt it to the Gallina language. With those done, the laws were relatively easy, falling into place over a two week period.

2015 Jun 12, all of the laws are complete.

So in all it took 1.5 years to learn Coq well enough and to find the right abstraction, and 2 weeks to do the actual work.

More Repositories

1

use-package

A use-package declaration for simplifying your .emacs
Emacs Lisp
4,399
star
2

git-scripts

A bunch of random scripts I've either written, downloaded or clipped from #git.
Shell
1,322
star
3

emacs-async

Simple library for asynchronous processing in Emacs
Emacs Lisp
832
star
4

git-from-the-bottom-up

An introduction to the architecture and design of the Git content manager
766
star
5

category-theory

An axiom-free formalization of category theory in Coq for personal study and practical work
Coq
744
star
6

dot-emacs

My .emacs.el file and other personal Emacs goodies
Emacs Lisp
606
star
7

alert

A Growl-like alerts notifier for Emacs
Emacs Lisp
426
star
8

nix-config

My local Nix configuration
Emacs Lisp
399
star
9

gitlib

Haskell
176
star
10

coq-haskell

A library for formalizing Haskell types and functions in Coq
Coq
159
star
11

org-mode

This is a very old fork of Org-mode, but it's the version I still use every day
Emacs Lisp
155
star
12

emacs-chess

A complete chess client written in Emacs Lisp.
Emacs Lisp
122
star
13

git-undo-el

A command for Emacs to regress or "undo" a region back through its Git history
Emacs Lisp
87
star
14

control-theory

Control theory in Haskell: Data structures, algorithms and adapters
Haskell
80
star
15

putting-lenses-to-work

A presentation for BayHac 2017 on how I uses lenses at work
Haskell
75
star
16

nix-update-el

An Emacs command for updating fetch declarations in place
Emacs Lisp
71
star
17

una

A universal interface to multiple unarchiving tools
Haskell
68
star
18

use-package-examples

Example declarations to demonstrate the features of use-package
52
star
19

regex-tool

A regular expression IDE for Emacs, to help with the creation and testing of regular expressions.
Emacs Lisp
50
star
20

git-annex-el

Emacs integration for the git-annex tool by Joey Hess
Emacs Lisp
43
star
21

notes

Haskell
42
star
22

z3cat

Use Conal Elliott's concat library to compile regular Haskell functions into Z3 equations
Haskell
38
star
23

emacs-release

A history of Emacs releases, under version control
Emacs Lisp
36
star
24

newartisans

HTML
35
star
25

emacs-pl

Emacs Lisp
31
star
26

bytestring-fiat

An implementation of the Haskell ByteString library using the Fiat system from MIT
Coq
31
star
27

periods

Common Lisp library for manipulating date/time objects at a higher level
Common Lisp
29
star
28

c2hsc

Utility for creating .hsc files from C API header files
Haskell
26
star
29

trade-journal

Code for keep an investment trade journal
Haskell
25
star
30

simple-conduit

Haskell
25
star
31

gdtoa

David M. Gay's floating-point conversion library
C
25
star
32

hours

Utility for showing hours worked within a work month against a target
Haskell
24
star
33

thinking-with-functions

A brief presentation on Denotational Design, based on Conal Elliott's work
Nix
23
star
34

comparable

A library for comparing data structures in Rust, oriented toward testing
Rust
21
star
35

async-pool

Haskell
21
star
36

parsec-free

Haskell
20
star
37

pushme

A script I use for synchronizing directories and ZFS pools between systems
Haskell
20
star
38

haskell-config

My haskell-mode configuration for Emacs
Emacs Lisp
19
star
39

categorical

Compiling to STLC to categories in Haskell and Coq, using Conal Elliot's work
Haskell
19
star
40

ghc-dynamic-example

An example of dynamically loading a Haskell source module
Haskell
18
star
41

scripts

Various and sundry shell scripts used on my system
Shell
17
star
42

linearscan

Coq
17
star
43

coq-lattice

A reflection-based proof tactic for lattices in Coq
Coq
16
star
44

git-all

Utility for finding all Git repositories that need attention
Haskell
16
star
45

coq-cds4ltl

A formalization of finite, constructive log analysis using linear temporal logic
Coq
16
star
46

springboard

An Emacs mode based on Helm that makes it easy to bounce around projects
Emacs Lisp
15
star
47

logging

Haskell
15
star
48

ready-lisp

A distribution of Aquamacs, SBCL and SLIME which offers the simplest way to run Common Lisp on Mac OS X
Emacs Lisp
14
star
49

haskell-to-c

Sample code to build a C library from a Haskell module, then call it from C
Haskell
12
star
50

markdown.net

A Markdown and SmartyPants processor written in C# for .NET.
C#
12
star
51

svndump

Library for parsing Subversion dump files from Haskell
Haskell
12
star
52

hello

Hello world project templates for getting started quickly with Nix
Nix
11
star
53

software-foundations

Nix-enabled and fully building mirror of Software Foundations WITHOUT SOLUTIONS
HTML
10
star
54

remember

A mode for Emacs which makes it easy to quickly jot down information.
Emacs Lisp
10
star
55

dirscan

Stateful directory scanning in Python. Makes a great ~/.Trash cleaner.
Python
9
star
56

pipes-files

Haskell
9
star
57

monad-extras

Haskell
9
star
58

cambl

Common Lisp library for working with commoditized amounts and balances
Common Lisp
9
star
59

sizes

Recursively show space (size and i-nodes) used in subdirectories
Haskell
9
star
60

disk-catalog

A Python script for cataloging offline media and disk archives.
Python
8
star
61

erc-yank

Automagically create a Gist in ERC if pasting more than 5 lines
Emacs Lisp
8
star
62

hierarchy

Haskell
8
star
63

simple-ltl

A simple compiler from LTL formulas to state machines
Haskell
7
star
64

linearscan-hoopl

Haskell
7
star
65

pcomplete

A programmable TAB completion facility for Emacs Lisp programmers. Used by Eshell.
Emacs Lisp
7
star
66

subconvert

A script to faithfully convert Subversion repositories to Git
C++
7
star
67

red-black

An efficient implementation of red-black trees for Common Lisp, by Jürgen Böhms Heimatseiten
Common Lisp
6
star
68

stringable

A Stringable type class, in the spirit of Foldable and Traversable
Haskell
6
star
69

gnus-harvest

Harvest e-mail addresses from read/written Gnus articles
Emacs Lisp
5
star
70

start-kadena

My own Nix script for starting and testing a Kadena node
Nix
5
star
71

ipcvar

Haskell
5
star
72

set-theory

Coq
5
star
73

pipes-async

Haskell
5
star
74

eval-expr

Enhanced eval-expression command
Emacs Lisp
5
star
75

planner

A day-planner-like planning tool for Emacs; uses Muse to publish plan pages.
Emacs Lisp
5
star
76

sacred-writings

A bilingual typesetting of the Hidden Words
TeX
4
star
77

sitebuilder

Common Hakyll builder for my websites
Haskell
4
star
78

bcalc

Haskell
4
star
79

refine-freer

Experiments with an extensible refinement framework
Coq
4
star
80

wallet

Information about staking and management ICP tokens on the Internet Computer
Nix
4
star
81

haskell-infra

Some files related to administration of Haskell infrastructure
4
star
82

firewall

A rigorous set of firewall scripts for BSD ipfw, and Linux iptables
Shell
4
star
83

linkdups

Intelligently hard-link duplicate files in a directory tree
Python
4
star
84

haskell-c-stack

Experiments to determine how the C stack relates to the Haskell FFI
Haskell
3
star
85

runmany

Run multiple commands, interleaving output and errors
Haskell
3
star
86

johnwiegley

My personal website, at johnwiegley.com
HTML
3
star
87

zomega

A computational reflection based solver for expressions involving Z (but tunable)
Coq
3
star
88

rehoo

Utility to combine lots and lots of .hoo files in parallel
Haskell
3
star
89

consistent

Haskell
3
star
90

sshify

Script for setting up publickey authentication on new hosts
Shell
3
star
91

monad-base-control

A rewrite of monad-control which provides only MonadBaseControl
Haskell
3
star
92

haskell-quantification

Presentation on quantification in Haskell for South Bay Haskell
Haskell
3
star
93

muse

The Emacs Muse, a complete publishing environment written for Emacs.
Emacs Lisp
3
star
94

helm-hoogle

Use helm to navigate query results from Hoogle
Emacs Lisp
2
star
95

org-beamer-template

A quick template from which to start new presentations
Emacs Lisp
2
star
96

aasaan

A library for transliterating between different representations of the Arabic alphabet.
C++
2
star
97

kleisli

Haskell
2
star
98

z3-generate-api

A tool to generate Haskell wrappers around the Z3 C API
Haskell
2
star
99

project-euler

My solutions to Project Euler in Haskell
Haskell
2
star
100

church-list

Haskell
2
star