Clamp
Type Classes for Substructural Types Edward Gan
Advisors: Greg Morrisett and Jesse Tov
April 16, 2013
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 1 / 16
Clamp Type Classes for Substructural Types Edward Gan Advisors: - - PowerPoint PPT Presentation
Clamp Type Classes for Substructural Types Edward Gan Advisors: Greg Morrisett and Jesse Tov April 16, 2013 Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 1 / 16 Statically Tracking State A common bug: Incorrect
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 1 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 2 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 3 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 4 / 16
◮ Break types τ into qualifier ξ and pretype τ, τ ::=ξ τ. ◮ ξ determines substructural properties. ◮ Verbose Polymorphism
◮ Assign types τ a kind κ that determines substructural properties, e.g.
◮ Polymorphism through subkinding, dependent kinds
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 5 / 16
◮ Uniform Meta-theory ◮ Cheap Polymorphism over U,R,A,L ◮ Easy to add-on stateful built-ins (s/w references) ◮ Orthogonal Implementation ◮ Type Classes! Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 6 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 7 / 16
◮ Always type safe
◮ Can be unsound if aliased
◮ swap: ref rqα × α
U
◮ sswap: ref sα × β
U
◮ release: ref rqα
U
◮ srelease: ref sα
U
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 8 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 9 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 10 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 11 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 12 / 16
Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 13 / 16
◮ Use memory efficiently ◮ Assume minimum number of Dup/Drop constraints
◮ Bottom up recursive ◮ Annotate to minimize number of assumptions required at each level ◮ Can prove: global memory usage minimized, no extraneous constraints Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 14 / 16
User Code Dup/Drop Insertion Type Inference Typeclass Instances Constraint Solving Generalized Type Scheme
◮ A dup/drop insertion pass ◮ Substructural type class instances ◮ Constraints to closure environments in the type inference step Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 15 / 16
◮ Simple theory and metatheory built on established tools ◮ Rich enough to encode URAL and strong/weak references easily ◮ Implementation piggybacks off Haskell
◮ Substructural inference algorithm independently interesting ◮ Type Classes are fun
◮ Custom dup/drop ◮ Arrow Polymorphism ◮ Runtime Considerations Edward Gan (Advisors: Greg Morrisett and Jesse Tov) Clamp April 16, 2013 16 / 16