ML letrec f xs = if null xs then nil else snoc (f (tl xs)) (hd xs) What type does this function have? null : ∀ ( list → bool) snoc : ∀ ( list → → list) hd, tl : ∀ ( list → ) nil : ∀ ( list)
Type Inference f : ∀ ( list → list) ● Given f, how can we infer this type? ● What does it even mean for a value to have a type? ● How can we be sure we have the most general type?
Algorithm W ● W attempts to build a substitution, bottom-up ● W can fail with an error if there is no valid typing ● Intuition: ○ Collect constraints ○ Then solve constraints ● Reality: W is the fusion of these two steps ● See the code!
Further Reading More type systems ● System F, F⍵ ● Rank-N types ● Type Classes ● Dependent Types ● Refinement Types Other approaches ● Constraints ● Bidirectional typechecking ● SMT See TAPL & ATAPL!