Eric Weinstein
February 24, 2019
57

# 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!

## Eric Weinstein

February 24, 2019

## Transcript

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

Santa Cruz, California, USA 24 February 2019

6. ### Dependent Types! A type whose deﬁnition 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

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

13. ### 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
14. ### 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/
15. ### 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
16. ### 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
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

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

general program equivalence is undecidable! !!
30. ### 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. ### TL;DPA Dependent types are amazing! Idris is an amazing language

and you should try it!!