Value Your Types!

Value Your Types!

You’re probably familiar with types in programming languages, such as “integer” or “list of integers.” But what if your type system were powerful enough to express types like “non-negative integer” or “list of strings where each string is at least eight characters long”? Welcome to the world of dependent types! In this talk, we’ll explore what dependent types are, how they work, and the relationship between type theory and predicate logic, all using the Idris programming language. We’ll even see when type checking can become (gasp) undecidable!

Facce030b679bda34eb7c64885a741fc?s=128

Eric Weinstein

February 24, 2019
Tweet

Transcript

  1. Va1u3 Your TYPES! A !!Con West Adventure Eric Weinstein UC

    Santa Cruz, California, USA 24 February 2019
  2. eric@testdouble.com

  3. @ericqweinstein

  4. @ericqweinstein

  5. "queue"

  6. Dependent Types! A type whose definition depends on a value

    "List of integers" is a type; "list of integers where each successive value is strictly larger than its predecessor" is a dependent type!
  7. History! 1934: Haskell Curry notices similarities between the typed lambda

    calculus and propositional logic 1960s: William Howard and Nicolaas De Bruijn extend Curry’s work to predicate logic
  8. History! Credit: https://manishearth.github.io/blog/2017/03/04/what-are-sum-product-and-pi-types/

  9. History! Credit: https://manishearth.github.io/blog/2017/03/04/what-are-sum-product-and-pi-types/ ∀x: fn() → Array<bool, x> "For all

    x, we can construct this array!" ∃x: fn() → Array<bool, x> "There exists an x such that we can construct this array!"
  10. History! 1934: Haskell Curry notices similarities between the typed lambda

    calculus and propositional logic 1960s: William Howard and Nicolaas De Bruijn extend Curry’s work to predicate logic
  11. History! 1934: Haskell Curry notices similarities between the typed lambda

    calculus and propositional logic 1960s: William Howard and Nicolaas De Bruijn extend Curry’s work to predicate logic
  12. The Curry-Howard Correspondence!

  13. None
  14. Idris! data Vect : Nat -> Type -> Type where

    Nil : Vect 0 a (::) : (x : a) -> (xs : Vect n a) -> Vect (n + 1) a Credit: https://en.wikipedia.org/wiki/Idris_(programming_language)#Dependent_types
  15. Idris! data Vect : Nat -> Type -> Type where

    Nil : Vect Z a (::) : a -> Vect n a -> Vect (S n) a Credit: https://www.idris-lang.org/example/
  16. Idris! total pairAdd : Num a => Vect n a

    -> Vect n a -> Vect n a pairAdd Nil Nil = Nil pairAdd (x :: xs) (y :: ys) = x + y :: pairAdd xs ys Credit: https://en.wikipedia.org/wiki/Idris_(programming_language)#Dependent_types
  17. Idris! total append : Vect n a => Vect m

    a -> Vect (n + m) a append Nil ys = ys append (x :: xs) ys = x :: append xs ys Credit: https://en.wikipedia.org/wiki/Idris_(programming_language)#Dependent_types
  18. Idris! total append : Vect n a => Vect m

    a -> Vect (n + m) a append Nil ys = ys append (x :: xs) ys = x :: append xs ys Credit: https://en.wikipedia.org/wiki/Idris_(programming_language)#Dependent_types
  19. Idris! Credit: https://github.com/HoTT/book/issues/743

  20. Aside! #

  21. # Aside!

  22. Aside! #

  23. Aside!

  24. Aside!

  25. Aside!

  26. ∴ Aside!

  27. ? ? ? Aside!

  28. Undecidable!

  29. Credit: The Princess Bride (1987)

  30. Undecidable! When types contain values, they become little programs... ...and

    general program equivalence is undecidable! !!
  31. Undecidable! "At compile-time it will only evaluate things which it

    knows to be total (i.e. terminating and covering all possible inputs) in order to keep type checking decidable." !! Credit: https://docs.idris-lang.org/en/latest/faq/faq.html
  32. None
  33. Papers! http://www.cse.chalmers.se/~peterd/papers/ DependentTypesAtWork.pdf https://dl.acm.org/citation.cfm?id=671431 http://www.cis.upenn.edu/~plclub/lambda-eek/lambda-eek.pdf http://www.kb.ecei.tohoku.ac.jp/~terauchi/papers/popl10- depceg.pdf

  34. TL;DPA Dependent types are amazing! Idris is an amazing language

    and you should try it!!
  35. Credit: DefendingDRealm (https://www.redbubble.com/)