Download presentation

Presentation is loading. Please wait.

Published byLayla Timm Modified over 3 years ago

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.(x z) 0 : S | x C x:X z:Z (CT-VAR) 0 : Nat | ø {} (CT-ZERO) x : _ | _ _ z : _ | _ _ (CT-APP) (x z) : _ | _ _ 0 : _ | _ _ (CT-APP) X | ø {}Z | ø {} Nat | ø {} V 1 | {V 1 } C 1 C 1 = {X = Z V 1 } = x:X,z:Z (x z) 0 : _ | _ (CT-ABS) C 2 = C 1 {V 1 = Nat V 2 } V 2 | {V 1, V 2 } C 2 X Z V 2 {V 1, V 2 } C2C2

9
Unifying the constraints Unify({X = Z V 1 }, {V 1 = Nat V 2 }) Unification fails or succeeds If succeeds then typeable = [X Z V 1, V 1 Nat V 2 ] (X Z V 2 ) = (Z (Nat V 2 )) Z V 2

10
Kind Inferencing example

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

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 DATA KindExpr | KVar | KStar | KCon | KApply DATA TypeExpr | TVar | TCon | TConProduct | TProduct | TPred | TQuant | TApply

16
Generalized AST Unify structure DATA GenExpr | GVar | GCon | GApply DATA KindExpr | KGenExpr gExpr :: GenExpr | KStar DATA TypeExpr | TGenExpr gExpr :: GenExpr | TConProduct | TProduct | TPred | TQuant

17
Kind abstract tree KindExpr KVarKApplyKConKStarKParen KindExpr KGenExprKStarKParen GenExpr GVarGApplyGCon GenExpr before unified

18
KindExpr KVar TypeExpr TVarTApplyKApply Unified tree GenExpr GVar KindExpr KGenExpr TypeExpr TGenExpr GApply before unified GenExpr

19
-- Pass 1, patterns/placeholders SEM KindExpr | KVar loc. (kpuniq,tai,kgam) = samefun @lhs.patTpTpConstrGam lhs. patTpTpConstrGam = @kgam SEM TypeExpr | TVar loc. (_,tai,tcgam) = samefun @lhs.patImTpConstrGam lhs. patImTpConstrGam = @tcgam

20
ATTR GenExpr [ | patImGenGam: {TypeAssumptions} | ] SEM GenExpr | GVar loc. (gpuniq,tai,ggam) = samefun @lhs.patImGenGam lhs. patImGenGam = @ggam SEM TypeExpr | TGenExpr gExpr. patImGenGam = @lhs.patImTpConstrGam lhs. patImTpConstrGam = @gExpr.patImGenGam SEM KindExpr | KGenExpr gExpr. patImGenGam = @lhs.patTpTpConstrGam lhs. patTpTpConstrGam = @gExpr.patImGenGam

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

Similar presentations

OK

Inheritance. Extending Classes It’s possible to create a class by using another as a starting point i.e. Start with the original class then add methods,

Inheritance. Extending Classes It’s possible to create a class by using another as a starting point i.e. Start with the original class then add methods,

© 2018 SlidePlayer.com Inc.

All rights reserved.

By using this website, you agree with our use of **cookies** to functioning of the site. More info in our Privacy Policy and Google Privacy & Terms.

Ads by Google

Ppt on e-library system Ppt on rolling friction Ppt on acute coronary syndrome treatment Ppt on railway track design Ppt on forest society and colonialism in india News editing ppt on ipad Ppt on capacity building of teachers Ppt on maths class 10 on real numbers Ppt on energy giving food for kids Ppt on food corporation of india