O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
Types:
Weak/Duck/Optional vs Strong/Strict
Let the War Begin!
Victor Polischuk
13 years of experience
Tech Leader
@alkovictor victor-cr
Infopulse
BICS
Types
Strong
Static
Manifest
Weak
Dynamic
Implicit
Static
Dynamic
Verification Phase
Java
C#
C
JavaScript
PHP
Groovy
Static
Dynamic
Implicit
Manifest
Type Inference
Haskell
Scheme
JavaScript
Java
Pascal
C
Implicit
Manifest
Strong
Weak
<TooManyDefinitionsException>
When you use “strong” in a sense of “static”
– you hurt a puppy
Strong
vs
Weak
Runtime type information
Restrict variable type
Type conversions
JavaScript
Java/Scala
C#
Type Strength/Weakness
JavaScript
Java/Scala
C#
Type Strength/Weakness
Type Safe
Well-typed program cannot “go
wrong”
•Arthur John Robin Gorell Milner
What Is “Type Safe”
Memory safe
Ensure proper semantic for operations
Formal Type System
•Context: {<v, T>,…,<v, T>}
•Operation: (T, …, T) -> T
Hey, you!! Tell them about lambda calculus!!!
Formalizing The Type System
Expression
𝑒 = 𝑥
𝑒 = 𝑒1(𝑒2)
𝑒 = 𝜆𝑥. 𝑒
𝑒 = 𝑙𝑒𝑡 𝑥 = 𝑒1 𝑖𝑛 𝑒2
Examples in Java
Variable: int x = y
Application: increment(x*y)
Abstraction: x -> x + 2
Substitution: ((Predicate) (x -> ...
Types
mono 𝜏 = 𝛼
mono 𝜏 = 𝐷 𝜏1 … 𝜏 𝑛
poly 𝜎 = 𝜏
poly 𝜎 = ∀𝛼. 𝜎
Examples in Java
Monotypic:
String
Map<Integer, Object>
Polytypic:
T
Map<String, T>
Predicate<T>
Function<T, K>
Context
Γ = ϵ
Γ = Γ, 𝑥: 𝜎
Dude
Context
Γ = {𝑥1: 𝜎1, … , 𝑥 𝑛: 𝜎 𝑛}
Typing
Formalizing The Type System
Variable Access:
𝑥:𝜎∈Γ
Γ⊢𝑥:𝜎
Application:
Γ⊢𝑒0∶𝜏→𝜏′ Γ⊢𝑒1:𝜏
Γ⊢𝑒0(𝑒1):𝜏′
Abstraction:
Γ, 𝑥:𝜏⊢𝑒:𝜏...
Free Type Variables
𝑓𝑟𝑒𝑒 𝛼 = 𝛼
𝑓𝑟𝑒𝑒 Γ =
𝑥:𝜎∈Γ
𝑓𝑟𝑒𝑒(𝜎)
Formalizing The Type System
Specialization:
Γ⊢𝑒:𝜎′ 𝜎′⊑𝜎
Γ⊢𝑒:𝜎
Generalization:
Γ⊢𝑒:𝜎 𝛼∉𝑓𝑟𝑒𝑒(Γ)
Γ⊢𝑒:∀𝛼.𝜎
Well Typed You Say?
There is a lot of math under the hood
Correctness can be proved
Tests are heuristics and have no future
Print All Permutations: JavaScript
Print All Permutations: Java
Print All Permutations: Java 8
Print All Permutations: JavaScript
Print All Permutations: Scala
Print All Permutations: Scala
Print All Permutations: C#
Print All Permutations: Haskell
So What Shall We Do?Learn
Math
Other Languages
Computer Science
Future
Project Valhalla
• Value types
• Improved generics
Correctness Proving
• Functions as first-class citizens
• Depend...
Questions
Thank you for attention
Types: Weak/Duck/Optional vs Strong/Strict. Let the War Begin!
Types: Weak/Duck/Optional vs Strong/Strict. Let the War Begin!
Próximos SlideShares
Carregando em…5
×

Types: Weak/Duck/Optional vs Strong/Strict. Let the War Begin!

204 visualizações

Publicada em

You probably have participated many times in those battles which language is better. Sometimes you definitely have been using "weak/strict typing" definition. I would like to talk about it. It is too important to ignore. I want to compare several different languages and show you how delusional those "weak/strong" definitions. We will meet some math along with Javascript, Java, Scala, C++, .Net, Haskel and several others on the way to the truth. We will spill some blood and may lose some comrades but as a reward survivors will touch the future (a bit) of nextgen languages (let's name it as features of Java 40.0).

Publicada em: Engenharia
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

Types: Weak/Duck/Optional vs Strong/Strict. Let the War Begin!

  1. 1. Types: Weak/Duck/Optional vs Strong/Strict Let the War Begin!
  2. 2. Victor Polischuk 13 years of experience Tech Leader @alkovictor victor-cr Infopulse BICS
  3. 3. Types Strong Static Manifest Weak Dynamic Implicit
  4. 4. Static Dynamic Verification Phase
  5. 5. Java C# C JavaScript PHP Groovy Static Dynamic
  6. 6. Implicit Manifest Type Inference
  7. 7. Haskell Scheme JavaScript Java Pascal C Implicit Manifest
  8. 8. Strong Weak <TooManyDefinitionsException>
  9. 9. When you use “strong” in a sense of “static” – you hurt a puppy
  10. 10. Strong vs Weak Runtime type information Restrict variable type Type conversions
  11. 11. JavaScript Java/Scala C# Type Strength/Weakness
  12. 12. JavaScript Java/Scala C# Type Strength/Weakness
  13. 13. Type Safe Well-typed program cannot “go wrong” •Arthur John Robin Gorell Milner
  14. 14. What Is “Type Safe” Memory safe Ensure proper semantic for operations
  15. 15. Formal Type System •Context: {<v, T>,…,<v, T>} •Operation: (T, …, T) -> T
  16. 16. Hey, you!! Tell them about lambda calculus!!!
  17. 17. Formalizing The Type System
  18. 18. Expression 𝑒 = 𝑥 𝑒 = 𝑒1(𝑒2) 𝑒 = 𝜆𝑥. 𝑒 𝑒 = 𝑙𝑒𝑡 𝑥 = 𝑒1 𝑖𝑛 𝑒2
  19. 19. Examples in Java Variable: int x = y Application: increment(x*y) Abstraction: x -> x + 2 Substitution: ((Predicate) (x -> x == 0)).apply(y)
  20. 20. Types mono 𝜏 = 𝛼 mono 𝜏 = 𝐷 𝜏1 … 𝜏 𝑛 poly 𝜎 = 𝜏 poly 𝜎 = ∀𝛼. 𝜎
  21. 21. Examples in Java Monotypic: String Map<Integer, Object> Polytypic: T Map<String, T> Predicate<T> Function<T, K>
  22. 22. Context Γ = ϵ Γ = Γ, 𝑥: 𝜎
  23. 23. Dude
  24. 24. Context Γ = {𝑥1: 𝜎1, … , 𝑥 𝑛: 𝜎 𝑛}
  25. 25. Typing
  26. 26. Formalizing The Type System Variable Access: 𝑥:𝜎∈Γ Γ⊢𝑥:𝜎 Application: Γ⊢𝑒0∶𝜏→𝜏′ Γ⊢𝑒1:𝜏 Γ⊢𝑒0(𝑒1):𝜏′ Abstraction: Γ, 𝑥:𝜏⊢𝑒:𝜏′ Γ⊢𝜆𝑥.𝑒:𝜏→𝜏′ Substitution: Γ⊢𝑒0∶𝜎 Γ, 𝑥:𝜎⊢𝑒1:𝜏 Γ⊢𝑙𝑒𝑡 𝑥=𝑒0 𝑖𝑛 𝑒1∶𝜏
  27. 27. Free Type Variables 𝑓𝑟𝑒𝑒 𝛼 = 𝛼 𝑓𝑟𝑒𝑒 Γ = 𝑥:𝜎∈Γ 𝑓𝑟𝑒𝑒(𝜎)
  28. 28. Formalizing The Type System Specialization: Γ⊢𝑒:𝜎′ 𝜎′⊑𝜎 Γ⊢𝑒:𝜎 Generalization: Γ⊢𝑒:𝜎 𝛼∉𝑓𝑟𝑒𝑒(Γ) Γ⊢𝑒:∀𝛼.𝜎
  29. 29. Well Typed You Say? There is a lot of math under the hood Correctness can be proved Tests are heuristics and have no future
  30. 30. Print All Permutations: JavaScript
  31. 31. Print All Permutations: Java
  32. 32. Print All Permutations: Java 8
  33. 33. Print All Permutations: JavaScript
  34. 34. Print All Permutations: Scala
  35. 35. Print All Permutations: Scala
  36. 36. Print All Permutations: C#
  37. 37. Print All Permutations: Haskell
  38. 38. So What Shall We Do?Learn Math Other Languages Computer Science
  39. 39. Future Project Valhalla • Value types • Improved generics Correctness Proving • Functions as first-class citizens • Dependent types
  40. 40. Questions Thank you for attention

×