Parametricity for Haskell with Imprecise Error Semantics Florian - - PowerPoint PPT Presentation

parametricity for haskell with imprecise error semantics
SMART_READER_LITE
LIVE PREVIEW

Parametricity for Haskell with Imprecise Error Semantics Florian - - PowerPoint PPT Presentation

Parametricity for Haskell with Imprecise Error Semantics Florian Stenger 1 and Janis Voigtl ander Technische Universit at Dresden TLCA09 = Applications 1 Supported by the DFG under grant VO 1512/1-1. Parametricity for Haskell with


slide-1
SLIDE 1

Parametricity for Haskell with Imprecise Error Semantics

Florian Stenger1 and Janis Voigtl¨ ander

Technische Universit¨ at Dresden

TLCA’09

= Applications

1Supported by the DFG under grant VO 1512/1-1.

slide-2
SLIDE 2

Parametricity for Haskell with Imprecise Error Semantics

Florian Stenger1 and Janis Voigtl¨ ander

Technische Universit¨ at Dresden

TLCA’09

= Applications

1Supported by the DFG under grant VO 1512/1-1.

slide-3
SLIDE 3

Reasoning in Haskell: An Example

takeWhile :: (α → Bool) → [α] → [α] takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ]

1

slide-4
SLIDE 4

Reasoning in Haskell: An Example

takeWhile :: (α → Bool) → [α] → [α] takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as)

1

slide-5
SLIDE 5

Reasoning in Haskell: An Example

takeWhile :: (α → Bool) → [α] → [α] takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) For every choice of p, f , and l: takeWhile p (map f l) = map f (takeWhile (p ◦ f ) l) Provable by induction.

1

slide-6
SLIDE 6

Reasoning in Haskell: An Example

takeWhile :: (α → Bool) → [α] → [α] takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) For every choice of p, f , and l: takeWhile p (map f l) = map f (takeWhile (p ◦ f ) l) Provable by induction. Or as a “free theorem” [Wadler, FPCA’89].

1

slide-7
SLIDE 7

Reasoning in Haskell: An Example

takeWhile :: (α → Bool) → [α] → [α] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) For every choice of p, f , and l: takeWhile p (map f l) = map f (takeWhile (p ◦ f ) l) Provable by induction. Or as a “free theorem” [Wadler, FPCA’89].

1

slide-8
SLIDE 8

Reasoning in Haskell: An Example

takeWhile :: (α → Bool) → [α] → [α] filter :: (α → Bool) → [α] → [α] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) For every choice of p, f , and l: takeWhile p (map f l) = map f (takeWhile (p ◦ f ) l) filter p (map f l) = map f (filter (p ◦ f ) l)

1

slide-9
SLIDE 9

Reasoning in Haskell: An Example

takeWhile :: (α → Bool) → [α] → [α] filter :: (α → Bool) → [α] → [α] g :: (α → Bool) → [α] → [α] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) For every choice of p, f , and l: takeWhile p (map f l) = map f (takeWhile (p ◦ f ) l) filter p (map f l) = map f (filter (p ◦ f ) l) g p (map f l) = map f (g (p ◦ f ) l)

1

slide-10
SLIDE 10

Errors in Haskell

2

slide-11
SLIDE 11

Errors in Haskell

◮ let average l = div (sum l) (length l)

in average [ ]

2

slide-12
SLIDE 12

Errors in Haskell

◮ let average l = div (sum l) (length l)

in average [ ]

◮ let tail (a : as) = as

in tail [ ]

2

slide-13
SLIDE 13

Errors in Haskell

◮ let average l = div (sum l) (length l)

in average [ ]

◮ let tail (a : as) = as

in tail [ ]

◮ if · · · then error “some string” else · · ·

2

slide-14
SLIDE 14

Errors in Haskell

◮ let average l = div (sum l) (length l)

in average [ ]

◮ let tail (a : as) = as

in tail [ ]

◮ if · · · then error “some string” else · · · ◮ let loop = loop

in loop

2

slide-15
SLIDE 15

Errors in Haskell

◮ let average l = div (sum l) (length l)

in average [ ]

◮ let tail (a : as) = as

in tail [ ]

◮ if · · · then error “some string” else · · · ◮ let loop = loop

in loop Traditionally, all error causes subsumed under “⊥”.

2

slide-16
SLIDE 16

Errors in Haskell

◮ let average l = div (sum l) (length l)

in average [ ]

◮ let tail (a : as) = as

in tail [ ]

◮ if · · · then error “some string” else · · · ◮ let loop = loop

in loop Traditionally, all error causes subsumed under “⊥”. Better, explicit distinction. Like: Ok v : nonerroneous Bad “· · · ” : finitely failing ⊥ : nonterminating

2

slide-17
SLIDE 17

Naive Propagation of Errors

◮ tail [1/0, 2.5] Ok ((Ok 2.5) : (Ok [ ]))

3

slide-18
SLIDE 18

Naive Propagation of Errors

◮ tail [1/0, 2.5] Ok ((Ok 2.5) : (Ok [ ])) ◮ (λx → 3) (error “· · · ”) Ok 3

3

slide-19
SLIDE 19

Naive Propagation of Errors

◮ tail [1/0, 2.5] Ok ((Ok 2.5) : (Ok [ ])) ◮ (λx → 3) (error “· · · ”) Ok 3 ◮ (error s) (· · · ) Bad s

3

slide-20
SLIDE 20

Naive Propagation of Errors

◮ tail [1/0, 2.5] Ok ((Ok 2.5) : (Ok [ ])) ◮ (λx → 3) (error “· · · ”) Ok 3 ◮ (error s) (· · · ) Bad s ◮ case (error s) of {· · · } Bad s

3

slide-21
SLIDE 21

Naive Propagation of Errors

◮ tail [1/0, 2.5] Ok ((Ok 2.5) : (Ok [ ])) ◮ (λx → 3) (error “· · · ”) Ok 3 ◮ (error s) (· · · ) Bad s ◮ case (error s) of {· · · } Bad s ◮ (error s1) + (error s2) ???

3

slide-22
SLIDE 22

Naive Propagation of Errors

◮ tail [1/0, 2.5] Ok ((Ok 2.5) : (Ok [ ])) ◮ (λx → 3) (error “· · · ”) Ok 3 ◮ (error s) (· · · ) Bad s ◮ case (error s) of {· · · } Bad s ◮ (error s1) + (error s2) ???

Dependence on evaluation order leads to considerably less freedom for implementors to rearrange computations, to optimise!

3

slide-23
SLIDE 23

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Basic idea: Ok v : nonerroneous Bad {· · · } : finitely failing, nondeterministic ⊥ : nonterminating

4

slide-24
SLIDE 24

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Basic idea: Ok v : nonerroneous Bad {· · · } : finitely failing, nondeterministic ⊥ : nonterminating Definedness order: Ok Bad ⊥

4

slide-25
SLIDE 25

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Basic idea: Ok v : nonerroneous Bad {· · · } : finitely failing, nondeterministic ⊥ : nonterminating Definedness order: Ok Bad ⊥

Bad e2 Bad e1 e2 ⊆ e1

4

slide-26
SLIDE 26

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Actual Propagation of Errors:

◮ (error s1) + (error s2) Bad {s1, s2}

5

slide-27
SLIDE 27

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Actual Propagation of Errors:

◮ (error s1) + (error s2) Bad {s1, s2} ◮ 3 + (error s) Bad {s}

5

slide-28
SLIDE 28

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Actual Propagation of Errors:

◮ (error s1) + (error s2) Bad {s1, s2} ◮ 3 + (error s) Bad {s} ◮ loop + (error s) ⊥

5

slide-29
SLIDE 29

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Actual Propagation of Errors:

◮ (error s1) + (error s2) Bad {s1, s2} ◮ 3 + (error s) Bad {s} ◮ loop + (error s) ⊥ ◮ (error s1) (error s2) Bad {s1, s2}

5

slide-30
SLIDE 30

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Actual Propagation of Errors:

◮ (error s1) + (error s2) Bad {s1, s2} ◮ 3 + (error s) Bad {s} ◮ loop + (error s) ⊥ ◮ (error s1) (error s2) Bad {s1, s2} ◮ (λx → 3) (error s) Ok 3

5

slide-31
SLIDE 31

Imprecise Error Semantics [Peyton Jones et al., PLDI’99]

Actual Propagation of Errors:

◮ (error s1) + (error s2) Bad {s1, s2} ◮ 3 + (error s) Bad {s} ◮ loop + (error s) ⊥ ◮ (error s1) (error s2) Bad {s1, s2} ◮ (λx → 3) (error s) Ok 3 ◮ case (error s1) of {(x, y) → error s2} Bad {s1, s2}

5

slide-32
SLIDE 32

Impact on Program Equivalence

“Normally”: takeWhile p (map f l) = map f (takeWhile (p ◦ f ) l) where: takeWhile :: (α → Bool) → [α] → [α] takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as)

6

slide-33
SLIDE 33

Impact on Program Equivalence

“Normally”: takeWhile p (map f l) = map f (takeWhile (p ◦ f ) l) where: takeWhile :: (α → Bool) → [α] → [α] takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) But now: takeWhile null (map tail (error s)) = map tail (takeWhile (null ◦ tail) (error s))

6

slide-34
SLIDE 34

Impact on Program Equivalence

“Normally”: takeWhile p (map f l) = map f (takeWhile (p ◦ f ) l) where: takeWhile :: (α → Bool) → [α] → [α] takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map :: (α → β) → [α] → [β] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) But now: takeWhile null (map tail (error s)) s = map tail (takeWhile (null ◦ tail) (error s)) s or “empty list”

6

slide-35
SLIDE 35

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] tail [ ] = error “empty list” tail (a : as) = as null [ ] = True null (a : as) = False

7

slide-36
SLIDE 36

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] tail [ ] = error “empty list” tail (a : as) = as null [ ] = True null (a : as) = False

7

slide-37
SLIDE 37

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] tail [ ] = error “empty list” tail (a : as) = as null [ ] = True null (a : as) = False

7

slide-38
SLIDE 38

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] tail [ ] = error “empty list” tail (a : as) = as null [ ] = True null (a : as) = False

7

slide-39
SLIDE 39

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] tail [ ] = error “empty list” tail (a : as) = as null [ ] = True null (a : as) = False

7

slide-40
SLIDE 40

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] tail [ ] = error “empty list” tail (a : as) = as null [ ] = True null (a : as) = False

7

slide-41
SLIDE 41

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] tail [ ] = error “empty list” tail (a : as) = as null [ ] = True null (a : as) = False

7

slide-42
SLIDE 42

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} while: takeWhile null (map tail (error s)) Bad {s} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) null [ ] = True null (a : as) = False

7

slide-43
SLIDE 43

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} while: takeWhile null (map tail (error s)) Bad {s} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) null [ ] = True null (a : as) = False

7

slide-44
SLIDE 44

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} while: takeWhile null (map tail (error s)) Bad {s} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) null [ ] = True null (a : as) = False

7

slide-45
SLIDE 45

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} while: takeWhile null (map tail (error s)) Bad {s} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) null [ ] = True null (a : as) = False

7

slide-46
SLIDE 46

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} while: takeWhile null (map tail (error s)) Bad {s} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) null [ ] = True null (a : as) = False

7

slide-47
SLIDE 47

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} while: takeWhile null (map tail (error s)) Bad {s} where: takeWhile p [ ] = [ ] takeWhile p (a : as) | p a = a : (takeWhile p as) | otherwise = [ ] map f [ ] = [ ] map f (a : as) = (f a) : (map f as) null [ ] = True null (a : as) = False

7

slide-48
SLIDE 48

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} while: takeWhile null (map tail (error s)) Bad {s} Thus: takeWhile null (map tail (error s)) = map tail (takeWhile (null ◦ tail) (error s))

7

slide-49
SLIDE 49

Impact on Program Equivalence

Because: takeWhile (null ◦ tail) (error s) Bad {s, “empty list”} while: takeWhile null (map tail (error s)) Bad {s} Thus: takeWhile null (map tail (error s)) = map tail (takeWhile (null ◦ tail) (error s)) Now, imagine this in the following program context: catchJust errorCalls (evaluate · · ·) (λs → if s == “empty list” then return [[42]] else return [ ])

7

slide-50
SLIDE 50

How to Revise Free Theorems?

[Wadler, FPCA’89] : for every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l)

8

slide-51
SLIDE 51

How to Revise Free Theorems?

[Wadler, FPCA’89] : for every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l)

◮ if f strict.

8

slide-52
SLIDE 52

How to Revise Free Theorems?

[Wadler, FPCA’89] : for every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l)

◮ if f strict.

[Johann & V., POPL’04] : in presence of seq, if additionally:

◮ p = ⊥ and ◮ f total.

8

slide-53
SLIDE 53

How to Revise Free Theorems?

[Wadler, FPCA’89] : for every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l)

◮ if f strict (f ⊥ = ⊥).

[Johann & V., POPL’04] : in presence of seq, if additionally:

◮ p = ⊥ and ◮ f total (∀x = ⊥. f x = ⊥).

8

slide-54
SLIDE 54

How to Revise Free Theorems?

[Wadler, FPCA’89] : for every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l)

◮ if f strict (f ⊥ = ⊥).

[Johann & V., POPL’04] : in presence of seq, if additionally:

◮ p = ⊥ and ◮ f total (∀x = ⊥. f x = ⊥).

What are corresponding conditions “in real”? Ok Bad ⊥

8

slide-55
SLIDE 55

Sweat and Tears . . .

. . . provide full formalisation of the semantic setup

9

slide-56
SLIDE 56

Sweat and Tears . . .

. . . provide full formalisation of the semantic setup . . . enter general proof of parametricity theorem

9

slide-57
SLIDE 57

Sweat and Tears . . .

. . . provide full formalisation of the semantic setup . . . enter general proof of parametricity theorem . . . consider the interesting induction cases

9

slide-58
SLIDE 58

Sweat and Tears . . .

. . . provide full formalisation of the semantic setup . . . enter general proof of parametricity theorem . . . consider the interesting induction cases . . . identify appropriate restrictions on the level of relations

9

slide-59
SLIDE 59

Sweat and Tears . . .

. . . provide full formalisation of the semantic setup . . . enter general proof of parametricity theorem . . . consider the interesting induction cases . . . identify appropriate restrictions on the level of relations . . . adapt relational actions

9

slide-60
SLIDE 60

Sweat and Tears . . .

. . . provide full formalisation of the semantic setup . . . enter general proof of parametricity theorem . . . consider the interesting induction cases . . . identify appropriate restrictions on the level of relations . . . adapt relational actions . . . complete general proof

9

slide-61
SLIDE 61

Sweat and Tears . . .

. . . provide full formalisation of the semantic setup . . . enter general proof of parametricity theorem . . . consider the interesting induction cases . . . identify appropriate restrictions on the level of relations . . . adapt relational actions . . . complete general proof . . . transfer restrictions to the level of functions

9

slide-62
SLIDE 62

Sweat and Tears . . .

. . . provide full formalisation of the semantic setup . . . enter general proof of parametricity theorem . . . consider the interesting induction cases . . . identify appropriate restrictions on the level of relations . . . adapt relational actions . . . complete general proof . . . transfer restrictions to the level of functions . . . apply to concrete functions

9

slide-63
SLIDE 63

. . . Application to takeWhile

For every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l)

10

slide-64
SLIDE 64

. . . Application to takeWhile

For every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l) provided

◮ p and f are nonerroneous,

Ok Bad ⊥

f p

10

slide-65
SLIDE 65

. . . Application to takeWhile

For every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l) provided

◮ p and f are nonerroneous, ◮ f ⊥ = ⊥,

Ok Bad ⊥

f p f

10

slide-66
SLIDE 66

. . . Application to takeWhile

For every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l) provided

◮ p and f are nonerroneous, ◮ f ⊥ = ⊥, ◮ f acts as identity on erroneous values, and

Ok Bad ⊥

f p f f f f

10

slide-67
SLIDE 67

. . . Application to takeWhile

For every g :: (α → Bool) → [α] → [α], g p (map f l) = map f (g (p ◦ f ) l) provided

◮ p and f are nonerroneous, ◮ f ⊥ = ⊥, ◮ f acts as identity on erroneous values, and ◮ f maps nonerroneous values to nonerroneous values.

Ok Bad ⊥

f p f f f f f

10

slide-68
SLIDE 68

Conclusion

Types:

◮ constrain the behaviour of programs ◮ thus lead to interesting theorems about programs

11

slide-69
SLIDE 69

Conclusion

Types:

◮ constrain the behaviour of programs ◮ thus lead to interesting theorems about programs

In a “real” language:

◮ interaction with language features can be quite nontrivial ◮ here: finite failures, imprecise semantics as in implementations

11

slide-70
SLIDE 70

Conclusion

Types:

◮ constrain the behaviour of programs ◮ thus lead to interesting theorems about programs

In a “real” language:

◮ interaction with language features can be quite nontrivial ◮ here: finite failures, imprecise semantics as in implementations

Not in the paper (but [Stenger & V., Technical Report]):

◮ inequational free theorems under weaker restrictions

11

slide-71
SLIDE 71

Conclusion

Types:

◮ constrain the behaviour of programs ◮ thus lead to interesting theorems about programs

In a “real” language:

◮ interaction with language features can be quite nontrivial ◮ here: finite failures, imprecise semantics as in implementations

Not in the paper (but [Stenger & V., Technical Report]):

◮ inequational free theorems under weaker restrictions ◮ dealing with exceptions in a limited way

11

slide-72
SLIDE 72

Conclusion

Types:

◮ constrain the behaviour of programs ◮ thus lead to interesting theorems about programs

In a “real” language:

◮ interaction with language features can be quite nontrivial ◮ here: finite failures, imprecise semantics as in implementations

Not in the paper (but [Stenger & V., Technical Report]):

◮ inequational free theorems under weaker restrictions ◮ dealing with exceptions in a limited way

Push further:

◮ proper exception handling in the IO monad

11

slide-73
SLIDE 73

Conclusion

Types:

◮ constrain the behaviour of programs ◮ thus lead to interesting theorems about programs

In a “real” language:

◮ interaction with language features can be quite nontrivial ◮ here: finite failures, imprecise semantics as in implementations

Not in the paper (but [Stenger & V., Technical Report]):

◮ inequational free theorems under weaker restrictions ◮ dealing with exceptions in a limited way

Push further:

◮ proper exception handling in the IO monad ◮ nondeterminism generally, not just on errors

11

slide-74
SLIDE 74

Conclusion

Types:

◮ constrain the behaviour of programs ◮ thus lead to interesting theorems about programs

In a “real” language:

◮ interaction with language features can be quite nontrivial ◮ here: finite failures, imprecise semantics as in implementations

Not in the paper (but [Stenger & V., Technical Report]):

◮ inequational free theorems under weaker restrictions ◮ dealing with exceptions in a limited way

Push further:

◮ proper exception handling in the IO monad ◮ nondeterminism generally, not just on errors ◮ systematic study of impact on other reasoning techniques

11

slide-75
SLIDE 75

References I

  • P. Johann and J. Voigtl¨

ander. Free theorems in the presence of seq. In Principles of Programming Languages, Proceedings, pages 99–110. ACM Press, 2004.

  • P. Johann and J. Voigtl¨

ander. A family of syntactic logical relations for the semantics of Haskell-like languages. Information and Computation, 207(2):341–368, 2009.

  • A. Moran, S.B. Lassen, and S.L. Peyton Jones.

Imprecise exceptions, Co-inductively. In Higher Order Operational Techniques in Semantics, Proceedings, volume 26 of ENTCS, pages 122–141. Elsevier, 1999.

12

slide-76
SLIDE 76

References II

S.L. Peyton Jones, A. Reid, C.A.R. Hoare, S. Marlow, and F. Henderson. A semantics for imprecise exceptions. In Programming Language Design and Implementation, Proceedings, pages 25–36. ACM Press, 1999.

  • F. Stenger and J. Voigtl¨

ander. Parametricity for Haskell with imprecise error semantics. Technical Report TUD-FI08-08, Technische Universit¨ at Dresden, 2008.

  • P. Wadler.

Theorems for free! In Functional Programming Languages and Computer Architecture, Proceedings, pages 347–359. ACM Press, 1989.

13