Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Hello, Type Systems! - Introduction to Featherweight Java

2,392 views

Published on

Shibuya Java #12 (August 1st, 2015)

Published in: Technology
  • Be the first to comment

Hello, Type Systems! - Introduction to Featherweight Java

  1. 1. Hello, Type Systems! Introduction to Featherweight Java Cheshire Cat (@y_taka_23) Shibuya Java #12 (Aug. 1, 2015)
  2. 2. Who Am I? ● HN: Cheshire Cat ● Twitter: @y_taka_23 ● GitHub: y-taka-23 ● Favorites ○ Formal methods ○ Functional programming
  3. 3. In the Era of Java 1.4 The following is compilable, but ... public static void main(String[] args) { List list = new ArrayList(); list.add(23); String str = (String) list.get(0); }
  4. 4. In the Era of Java 1.4 Implicite upcast from int to Object public static void main(String[] args) { List list = new ArrayList(); list.add(23); String str = (String) list.get(0); }
  5. 5. In the Era of Java 1.4 Downcast from Object to String public static void main(String[] args) { List list = new ArrayList(); list.add(23); String str = (String) list.get(0); }
  6. 6. In the Era of Java 1.4 Run-time exception!! public static void main(String[] args) { List list = new ArrayList(); list.add(23); String str = (String) list.get(0); }
  7. 7. What is the “Type Safety”?
  8. 8. Featherweight Java (FJ) ● Introduced by IGARASHI et al. (2002) ● Formalized & minimalized model ● Many features are omitted, e.g. ○ Assignment ○ Interfaces ○ Exceptions ● “Functional” fragment of Java
  9. 9. Three Points to Understand FJ 1. Expressions: What is the “programs”? 2. Typing: What is the “type check”? 3. Reduction: What is the “execution”?
  10. 10. Expressions ● Variables ● Constructors ● Field accesses ● Method invocations ● Casts x1, x2, ... new C(e1, ..., en) e.f e.m(x1, ..., xn) (C)e
  11. 11. Typing Rules Example: Rule for field accesses Gamma |- e0 : C0 fields(C0) = C1 f1, ..., Cn fn -------------------------------- Gamma |- e0.fi : Ci
  12. 12. Typing Rules Premise Gamma |- e0 : C0 fields(C0) = C1 f1, ..., Cn fn -------------------------------- Gamma |- e0.fi : Ci
  13. 13. Typing Rules Conclusion Gamma |- e0 : C0 fields(C0) = C1 f1, ..., Cn fn -------------------------------- Gamma |- e0.fi : Ci
  14. 14. Typing Rules Type env: Map from variable names to types Gamma |- e0 : C0 fields(C0) = C1 f1, ..., Cn fn -------------------------------- Gamma |- e0.fi : Ci
  15. 15. Typing Rules If e0 has type C0 under Gamma, Gamma |- e0 : C0 fields(C0) = C1 f1, ..., Cn fn -------------------------------- Gamma |- e0.fi : Ci
  16. 16. Typing Rules and fields of class C0 are Gamma |- e0 : C0 fields(C0) = C1 f1, ..., Cn fn -------------------------------- Gamma |- e0.fi : Ci
  17. 17. Typing Rules f1, ..., fn of classes C1, ..., Cn, Gamma |- e0 : C0 fields(C0) = C1 f1, ..., Cn fn -------------------------------- Gamma |- e0.fi : Ci
  18. 18. Typing Rules then e0.fi has type Ci under Gamma Gamma |- e0 : C0 fields(C0) = C1 f1, ..., Cn fn -------------------------------- Gamma |- e0.fi : Ci
  19. 19. Reduction Rules Example: Rule for field accesses fields(C) = C1 f1, ..., Cn fn -------------------------------- (new C(e1, ..., en)).fi -> ei
  20. 20. Reduction Rules Premise fields(C) = C1 f1, ..., Cn fn -------------------------------- (new C(e1, ..., en)).fi -> ei
  21. 21. Reduction Rules Conclusion fields(C) = C1 f1, ..., Cn fn -------------------------------- (new C(e1, ..., en)).fi -> ei
  22. 22. Reduction Rules If fields of class C are ... fields(C) = C1 f1, ..., Cn fn -------------------------------- (new C(e1, ..., en)).fi -> ei
  23. 23. Reduction Rules f1, ..., fn of classes C1, ..., Cn, fields(C) = C1 f1, ..., Cn fn -------------------------------- (new C(e1, ..., en)).fi -> ei
  24. 24. Reduction Rules then(new ...).fi reduces to ei fields(C) = C1 f1, ..., Cn fn -------------------------------- (new C(e1, ..., en)).fi -> ei
  25. 25. “Type Safety” in FJ If an expression e satisfies: ● e has a type without the two “impolite” rules ● e -> ... -> e’ ● No expression e’’ such that e’ -> e’’ Then e’ must be “completely reduced”, i.e. ● e consists of only constructors
  26. 26. Summary ● FJ is the “minimum” model of Java ● “Type safety” is the consistency of ○ Typing rules ○ Reduction rules ● We can discuss properties of programming languages by formalization
  27. 27. Have a Nice Typing! Presented by Cheshire Cat (@y_taka_23)

×