Download presentation
Presentation is loading. Please wait.
1
Strict Bidirectional Type Checking Adam Chlipala, Leaf Petersen, and Robert Harper
2
1/10/052 Type Systems Less Type Annotation More Type Annotation ML Concise syntax. Compact representation. Complex (global) type reconstruction problem. Undecidable past a certain point. Verbose syntax. Representation issues. Simple or no type reconstruction. Powerful type systems are still decidable. Haskell Java TILT IL
3
1/10/053 Type Systems Less Annotation More Annotation ML Concise (enough) syntax. Compact representation. Simple syntax directed typechecking. Powerful and decidable type systems. Haskell Java TILT IL Pierce, Turner (POPL ‘98)
4
1/10/054 Simply Typed Calculus
5
1/10/055 TermsTypes 10
6
1/10/056 TermsTypes 10 23
7
1/10/057 TermsTypes 10 23 38
8
1/10/058 TermsTypes 10 23 38 415
9
1/10/059 TermsTypes 10 23 38 415 …… ii 2 -1 Quadratic!
10
1/10/0510 Algorithmic view Inputs are black. Outputs are red.
11
1/10/0511 Algorithmic view Inputs are black. Outputs are red. Redundant
12
1/10/0512 Algorithmic view Inputs are black. Outputs are red.
13
1/10/0513 Algorithmic view Inputs are black. Outputs are red. Redundant
14
1/10/0514 Bidirectional Typechecking Synthesis: Typed terms. Analysis: Checkable terms.
15
1/10/0515 TermsTypes 11
16
1/10/0516 TermsTypes 11 23
17
1/10/0517 TermsTypes 11 23 35
18
1/10/0518 TermsTypes 11 23 35 47
19
1/10/0519 TermsTypes 11 23 35 47 …… i2i-1 Linear!
20
1/10/0520 Unnecessary! Much simpler technique works fine. Good asymptotic behavior. Syntax directed. Extends directly to sum types.
21
1/10/0521 Recursive types.
22
1/10/0522 Simple term
23
1/10/0523
24
1/10/0524 Fold Annotations Only
25
1/10/0525 With Sum Annotations
26
1/10/0526 Bidirectional version
27
1/10/0527 Let Binding Surprisingly, bidirectional typechecking interacts badly with let binding. –Quadratic increase in annotation size in bad cases. Bad - programmers use let. Bad - compilers use let. –Put code in “named form” (sequentialization)
28
1/10/0528 Binding forms Analysis binding: Synthesis binding:
29
1/10/0529
30
1/10/0530
31
1/10/0531
32
1/10/0532 Sequentializing bidirectional terms may lead to quadratic increase in type size!
33
1/10/0533 Binding forms (revisited) Analysis binding: – Synthesis binding: – Undecorated analysis binding? – –Might solve our problem.
34
1/10/0534
35
1/10/0535
36
1/10/0536
37
1/10/0537 Can we typecheck it?
38
1/10/0538
39
1/10/0539
40
1/10/0540
41
1/10/0541
42
1/10/0542 Key points: Typecheck body first. Context of occurrence gives a unique type to z 0 because it occurs in an analysis position.
43
1/10/0543 Algorithmically Speaking Divide context into input and output zones. Input zone variables must declare types. –Explicitly: –Implicitly: Output zone variables get types from occurrences: – –Check A after getting type for u from E. –Must ensure variables actually occur!!
44
1/10/0544 Formally Look to strict logic –Substructural logic in which hypotheses must be used at least once. Normal variables in unrestricted context ( may occur zero or more times. Strict variables in restricted context ( must occur at least once. Contrast with linear logic: –Linear variables in restricted context ( ) must occur exactly once.
45
1/10/0545 Strict Bidirectional Typechecking Judgments: –Analysis: –Synthesis: Unrestricted context ( is input mapping variables to their types. Restricted context ( is output mapping variables to their types. Strict variables must occur in analysis positions.
46
1/10/0546 Cool Fact #1 Theorem: The strict bidirectional typechecking rules constitute an algorithm. –Syntax directed. –Uniquely determined outputs. –Proof is in paper.
47
1/10/0547 Cool Fact #2 Theorem: Sequentialization into the strict language never increases type size. –Size of sequentialized form is bounded above by the size of the original. –Proof is in paper.
48
1/10/0548 Recap Bidirectional representation yields asymptotic improvements in type size. Let binding destroys these benefits. Recognizing strictness allows benefits to be recaptured without unification.
49
1/10/0549 The End
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.