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

Post on 15-Apr-2017

680 views 2 download

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

Types:Weak/Duck/Optional vs

Strong/StrictLet the War Begin!

Victor Polischuk

13 years of experience

Tech Leader

@alkovictor victor-cr

Infopulse

BICS

Types

Strong

Static

Manifest

Weak

Dynamic

Implicit

StaticDynamic

Verification Phase

JavaC#C

JavaScriptPHPGroovy

Stati

cDynam

ic

ImplicitManifest

Type Inference

HaskellSchemeJavaScript

JavaPascalC

Impl

icit

Manifest

StrongWeak

<TooManyDefinitionsException>

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

– you hurt a puppy

Strongvs

Weak

Runtime type information

Restrict variable type

Type conversions

JavaScriptJava/Scala

C#

Type Strength/Weakness

JavaScriptJava/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

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

Types

mono mono

poly poly

Examples in JavaMonotypic:

StringMap<Integer, Object>

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

Context

Dude

Context

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

Typing

Γ⊢𝑒 :𝜎

Formalizing The Type SystemVariable Access:

Application: Abstraction:

Substitution:

Free Type Variables

Formalizing The Type System

Specialization:

Generalization:

Not sure

I’ve got the idea

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?Le

arn Math

Other Languages

Computer Science

Future

Project Valhalla• Value types• Improved generics

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

QuestionsThank you for attention