LEARN DEPENDENTLY- TYPED PROGRAMMING WITH IDRIS WHO I AM - - PowerPoint PPT Presentation

learn dependently typed programming
SMART_READER_LITE
LIVE PREVIEW

LEARN DEPENDENTLY- TYPED PROGRAMMING WITH IDRIS WHO I AM - - PowerPoint PPT Presentation

LEARN DEPENDENTLY- TYPED PROGRAMMING WITH IDRIS WHO I AM @puffnfresh Tiny contributor to Idris (18 commits) Played with dependent types for 2 years Been doing Idris for 6 months ASSUMPTIONS Small experience with Haskell


slide-1
SLIDE 1

LEARN DEPENDENTLY- TYPED PROGRAMMING

WITH IDRIS

slide-2
SLIDE 2

WHO I AM

slide-3
SLIDE 3

▸ @puffnfresh ▸ Tiny contributor to Idris (18 commits) ▸ Played with dependent types for 2 years ▸ Been doing Idris for 6 months

slide-4
SLIDE 4

ASSUMPTIONS

slide-5
SLIDE 5

▸ Small experience with Haskell ▸ Have an install of Idris (can be tricky)

slide-6
SLIDE 6

$ brew install ghc cabal-install $ cabal update $ cabal install alex $ cabal install idris

slide-7
SLIDE 7
slide-8
SLIDE 8

OUTLINE

slide-9
SLIDE 9
  • 1. Overview of dependent types and Idris
  • 2. Work through exercises, I lead
  • 3. Work through exercises, I help
slide-10
SLIDE 10

MOTIVATION

slide-11
SLIDE 11

Bad news: most software canoot be reasoned about

— Paul Phillips

slide-12
SLIDE 12

▸ Curry-Howard; programs are proofs ▸ Let's make our proofs interesting ▸ Therefore let's use a powerful type system

slide-13
SLIDE 13

MISCONCEPTIONS

slide-14
SLIDE 14

▸ Idris is harder than Haskell ▸ Dependent types are hard

slide-15
SLIDE 15

DEPENDENT TYPES

EVERYTHING IS A TERM

slide-16
SLIDE 16

isIdris : Bool isIdris = True

  • ne : Nat
  • ne = if isIdris then S Z else Z

StringList : Type StringList = if isIdris then List Char else Int

slide-17
SLIDE 17

▸ Types and kinds are values in universes ▸ Types can depend on values ▸ Fref polymorphism, type constructors

slide-18
SLIDE 18

the : (t : Type) -> (x : t) -> t the _ a = a

  • ne : Nat
  • ne = the Nat Z
slide-19
SLIDE 19

id1 : {t : Type} -> (x : t) -> t id1 {t} a = a id2 : (x : t) -> t id2 a = a id3 : t -> t id3 a = a

slide-20
SLIDE 20

Option : Type -> Type Option = Maybe

slide-21
SLIDE 21

TOTALITY

slide-22
SLIDE 22

$ idris --total $ idris --warnpartial %default total total plusOne : Nat -> Nat plusOne Z = S Z plusOne (S n) = S (S n)

slide-23
SLIDE 23

I am often asked ‘how do I implement a server as a program in your terminating language?’

— Conor McBride

slide-24
SLIDE 24

I reply that I do not: a server is a coprogram in a language guarantefing livenest

— Conor McBride

slide-25
SLIDE 25

▸ We always make progress ▸ Watch out for the totality checker! ▸ Church-Rosser theorem ▸ Evaluation is really normalisation! ▸ Can still do it all!

slide-26
SLIDE 26

EQUALITY

slide-27
SLIDE 27

data (=) : a -> b -> Type where refl : x = x x : 1 = 1 x = refl y : 1 + 1 = 2 y = refl

slide-28
SLIDE 28

x : {a : Nat} -> a - a = Z x {a=Z} = refl x {a=S k} = x {a=k} y : {a : Nat} -> a - a = Z y {a} = replace {P = \x => (a - x = Z)} (plusZeroRightNeutral a) (minusPlusZero a Z)

slide-29
SLIDE 29

x : {a : Nat} -> a - a = Z x = ?xproof xproof = proof intros rewrite (minusPlusZero a Z) rewrite (plusZeroRightNeutral a) trivial

slide-30
SLIDE 30

▸ The problem of dependent types ▸ Values are unified ▸ Checked for syntactic/term equality

slide-31
SLIDE 31

WHY IDRIS?

slide-32
SLIDE 32

▸ LLVM, C, Java, JS backends ▸ FFI ▸ Lots of syntactic sugar ▸ Tactic rewriting ▸ Allows more lying/cheating ▸ REPL, editor modes, doc tools

slide-33
SLIDE 33
slide-34
SLIDE 34
slide-35
SLIDE 35

HOW TO IDRIS

slide-36
SLIDE 36

▸ Idris Tutorial ▸ Idris library docs ▸ Idris library source ▸ Beginning Haskell: a Project Based Approach

slide-37
SLIDE 37

LET'S GO

slide-38
SLIDE 38

▸ printf ▸ Equality proofs ▸ Verified algebra ▸ Vector filtering

slide-39
SLIDE 39

http://goo.gl/gfCJne