Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Hitchiker's Guide to the Curry-Howard Corre...

The Hitchiker's Guide to the Curry-Howard Correspondence

Functions are proofs.

Um, I can see how that might work. Go on.

Types are propositions. Really? In what sense?

In fact, a function is the proof of the proposition its type represents.

Woah, you've lost me now.

Don't Panic!

The Curry-Howard Correspondence is an elegant bridge between the planet of logic and the planet of programming, and it's not actually that hard to understand.

In this talk I'll use the Idris dependently-typed functional programming language for examples, as its type system is sophisticated enough to construct interesting automated proofs simply by writing functions. This talk is not designed to convert you into a theoretical computer scientist, but to share with you a wonderful sight in your journey through the vast and peculiar universe of programming.

A familiarity with functional programming would be useful for appreciating this talk, but it will not require any significant prior study of theoretical computer science.

Chris Ford

June 27, 2014
Tweet

Other Decks in Programming

Transcript

  1. Number of papers published today by the foremost expert on

    the Curry-Howard correspondence... 1
  2. chr : Integer ­> Char Idris> apply chr 65 'A'

    : Char (3==) : Integer ­> Bool Idris> apply (3==) 4 False : Bool
  3. length : List a ­> Integer (3==) : Integer ­>

    Bool Idris> comp length (3==) : List a ­> Bool
  4. ⊥ AnythingGoes : Type AnythingGoes = (a : Type) ­>

    a cantProveItAll : AnythingGoes ­> _|_ cantProveItAll f = f _|_
  5. NullPointerException council.office.Lock.acquire (Lock.java:42) council.office.FilingCabinet.find (FilingCabinet.java:42) council.office.Leopard.beware (Leopard.java:42) council.office.Lavatory.find (Lavatory.java:42) council.office.Cellar.find

    (Cellar.java:42) council.office.Consultation.post (Consultation.java:42) council.policy.Bypass.plan (Bypass.java:42) council.policy.ExpansionManager.execute (ExpansionManager.java:42) council.policy.Budget.spend (Budget.java:42)
  6. Type Nat = Z or (S Nat) Type List =

    [] or (x :: List) data Vect : Nat ­> Type ­> Type where Nil : Vect Z a (::) : (x : a) ­> (xs : Vect n a) ­> Vect (S n) a
  7. List : Type ­> Type [3, 4] : List Integer

    Vect : Nat ­> Type ­> Type [3, 4] : Vect 2 Integer
  8. head : Vect (S n) a ­> a head (x::_)

    = x Idris> head [] Can't unify Vect 0 a with Vect (S n) iType
  9. concat : Vect m a ­> Vect n a ­>

    Vect (m + n) a concat [] ys = ys concat (x::xs) ys = concat xs ys
  10. concat : Vect m a ­> Vect n a ­>

    Vect (m + n) a concat [] ys = ys concat (x::xs) ys = x::concat xs ys
  11. data Even : Nat ­> Type where Zero : Even

    Z Next : Even n ­> Even (S (S n)) Zero : Even Z Next (Next (Next Zero)) : Even 6
  12. total add : Even m ­> Even n ­> Even

    (m + n) add Zero y = y add (Next x) y = Next (add x y)
  13. total add : Multiple m a ­> Multiple m b

    ­> Multiple m (a + b) add (NoneOf _) y = y add (Next x) y ?= add x (Next y) Main.add_lemma_1 = proof intros rewrite plusAssociative n m b rewrite sym $ plusCommutative m b trivial
  14. total fortyTwoIsEven : Even 42 fortyTwoIsEven = mul 21 (Next

    Zero) where mul : (n:Nat) ­> Even m ­> Even (n*m) mul Z _ = Zero mul (S n) e = add e (mul n e)
  15. total threeAintEven : Even 3 ­> _|_ threeAintEven (Next e)

    with (e) | (Next _) impossible | Zero impossible
  16. ()

  17. References Edwin Brady Programming in Idris: A Tutorial idris-lang.org Brian

    McKenna EvenOdd in Agda, Idris, Haskell, Scala brianmckenna.org Philip Wadler Propositions as Types – updated today! wadler.blogspot.co.uk