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

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

Embed Size (px)

Citation preview

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

Types:Weak/Duck/Optional vs

Strong/StrictLet the War Begin!

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

Victor Polischuk

13 years of experience

Tech Leader

@alkovictor victor-cr

Infopulse

BICS

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

Types

Strong

Static

Manifest

Weak

Dynamic

Implicit

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

StaticDynamic

Verification Phase

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

JavaC#C

JavaScriptPHPGroovy

Stati

cDynam

ic

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

ImplicitManifest

Type Inference

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

HaskellSchemeJavaScript

JavaPascalC

Impl

icit

Manifest

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

StrongWeak

<TooManyDefinitionsException>

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

When you use “strong” in a sense of “static”

– you hurt a puppy

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

Strongvs

Weak

Runtime type information

Restrict variable type

Type conversions

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

JavaScriptJava/Scala

C#

Type Strength/Weakness

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

JavaScriptJava/Scala

C#

Type Strength/Weakness

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

Type Safe

Well-typed program cannot “go wrong”

•Arthur John Robin Gorell Milner

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

What Is “Type Safe”

Memory safe

Ensure proper semantic for operations

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

Formal Type System

•Context: {<v, T>,…,<v, T>}•Operation: (T, …, T) -> T

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

Hey, you!! Tell them about lambda calculus!!!

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

Formalizing The Type System

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

Expression

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

Examples in JavaVariable: int x = yApplication: increment(x*y)Abstraction: x -> x + 2Substitution: ((Predicate) (x -> x == 0)).apply(y)

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

Types

mono mono

poly poly

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

Examples in JavaMonotypic:

StringMap<Integer, Object>

Polytypic:TMap<String, T>Predicate<T>Function<T, K>

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

Context

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

Dude

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

Context

Γ={𝑥1:𝜎1 ,…,𝑥𝑛 :𝜎 𝑛 }

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

Typing

Γ⊢𝑒 :𝜎

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

Formalizing The Type SystemVariable Access:

Application: Abstraction:

Substitution:

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

Free Type Variables

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

Formalizing The Type System

Specialization:

Generalization:

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

Not sure

I’ve got the idea

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

Well Typed You Say?

There is a lot of math under the hood

Correctness can be proved

Tests are heuristics and have no future

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

Print All Permutations: JavaScript

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

Print All Permutations: Java

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

Print All Permutations: Java 8

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

Print All Permutations: JavaScript

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

Print All Permutations: Scala

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

Print All Permutations: Scala

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

Print All Permutations: C#

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

Print All Permutations: Haskell

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

So What Shall We Do?Le

arn Math

Other Languages

Computer Science

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

Future

Project Valhalla• Value types• Improved generics

Correctness Proving• Functions as first-class citizens• Dependent types

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

QuestionsThank you for attention