1 / 21

Unifying Kind and Type Inference

Unifying Kind and Type Inference. Remko van Beusekom & Jeroen Gordijn. Overview. Type inferencing Kind inferencing Example Similarities kind and type inferencing. Overview (2). Implementation problem in uhc Our solution to the problem Conclusion. Approach.

dacia
Download Presentation

Unifying Kind and Type Inference

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unifying Kind and Type Inference Remko van Beusekom & Jeroen Gordijn

  2. Overview • Type inferencing • Kind inferencing • Example • Similarities kind and type inferencing

  3. Overview (2) • Implementation problem in uhc • Our solution to the problem • Conclusion

  4. Approach • Investigate type and kind inferencing • Check the similarities • Investigate the implementations in UHC • Check whether unification is possible

  5. Type inferencing • Check if an (untyped) term can be typed e.g.: (\x.x+1) true can’t be typed (\x.x+1) 2 can be typed.

  6. Kind inferencing • Kinds are “the types of types” • Check if a type definition can be kinded e.g.: (Bool)(Nat)Can’t be kinded (Nat->Bool)(Nat)Can be kinded

  7. Type Inferencing example

  8.  = x:X,z:Z C1 = {X = ZV1} C2 = C1 {V1 = Nat V2} x:X   z:Z   (CT-VAR) (CT-VAR)  x : _ |_ _ X |ø {}  z : _ |_ _ Z |ø {} (CT-APP) 0 : Nat |ø {} V1 |{V1} C1 (CT-ZERO)   (x z) : _ |_ _  0 : _ |_ _ Nat |ø {} (CT-APP)  (x z) 0 : _ |_ _ V2 |{V1,V2} C2 (CT-ABS) X Z V2 C2 {V1,V2}  \x:X.\z:Z.(x z) 0 : S | x C

  9. Unifying the constraints • Unify({X = Z V1}, {V1 = Nat V2}) • Unification fails or succeeds • If succeeds then typeable •  = [X  Z  V1, V1Nat  V2] • (X  Z  V2) = (Z  (Nat  V2))  Z  V2

  10. Kind Inferencing example

  11.  = X:: _ ,Y:: _ *  * * Y :: _   X :: _  _   *  * * (K-TVAR) (K-TVAR)   X :: _  _ *  *   Y :: _ * (K-APP)   X Y :: _ (K-ABS) 2x *  \X.\Y.X Y :: K (*  *)  *  *

  12. Similarities • Walk over the tree. (BOTH) • Introduce placeholders for types/kinds (BOTH) • Introduce placeholders for Constraints (TYPE) • Fill the environment (BOTH) • Fill in the placeholders (BOTH)

  13. The challenge • Type inferencing implemented first • Kind inferencing added by copying parts from type inferencing • Duplicate code • Q: Can we unify these implementations?

  14. Solution to the problem • Generalize the AST • put common constructors in general data type • extra general constructor • Move inferencing code into general code • Problem: extra node in the generalised AST

  15. Implementation in UHC • Different structure

  16. Generalized AST • Unify structure

  17. before unified GenExpr KindExpr KGenExpr KStar KParen GVar GApply GCon GenExpr Kind abstract tree KindExpr KVar KApply KCon KStar KParen

  18. before unified KindExpr TypeExpr GenExpr KGenExpr TGenExpr GVar GApply GenExpr GenExpr Unified tree TypeExpr KindExpr KVar KApply TVar TApply

  19. Conclusion • Not tested, but this should work • Draw back: Lot of work now • Improvement: Future additions/fixes easier

More Related