type systems

Post on 16-Jul-2015

380 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Type SystemsDaniel Quirino Oliveira

daniel@nullability.org

Tuesday, January 18, 2011

What?

Tuesday, January 18, 2011

A set of syntatic constraints and rules that classifies programming language statements according to that values they deal with by associating types to values.

Tuesday, January 18, 2011

Purpose?

Tuesday, January 18, 2011

Check and prove a program correctness

Tuesday, January 18, 2011

Wait, wait... What’s type?

Tuesday, January 18, 2011

Intuitively...A set of values something may assumeA set of operations something may do

Or both

Tuesday, January 18, 2011

Label and a set of properties used by a type system to prove

program's correctness

Tuesday, January 18, 2011

Types of Type Systems

Tuesday, January 18, 2011

Monomorphiceach constant/variable/function may assume an unique type according to its value

Tuesday, January 18, 2011

e.g.: Pascal, C

procedure foo() begin foo := 10;end

i : integer;c : character;

i := 42;c := ‘a’;

int foo() { return 10;}

int i = 42;char c = ‘a’;

Tuesday, January 18, 2011

Polymorphiceach constant/variable/function may assume more than one type, given its value, according to context

Tuesday, January 18, 2011

e.g.: Java, C# ...

Number toNumber(int a) { return new Integer(a);}

Number toNumber(double b) { return new Double(b);}

Number a = toNumber(42);Number b = toNumber(4.2);Double c = (Double) b;Integer d = (Integer) a;

Tuesday, January 18, 2011

So, what static/dynamic... typing is about?

Tuesday, January 18, 2011

Type CHECKING!

Tuesday, January 18, 2011

Static Type Checking SystemA given variable is allowed assume only one TYPE in a given context

All program types are checked at least once by a “compiler” during the semantic analysis (parsing)

Tuesday, January 18, 2011

Remember that...

Tuesday, January 18, 2011

e.g.: Java, Scala

void foo() { Integer a = 42; String a = “hello”;}

def foo()= { var a = 0; a = “hello”;}

compile-time errorSymbol “a” already defined as being of another type.

run/compile-time errorSymbol “a” already defined as being of another type.

Tuesday, January 18, 2011

Dynamic Type Checking SystemA given variable may assume values of different TYPES in a given context during the program flow

I.e., values do have TYPES whereas variables have VALUES

Tuesday, January 18, 2011

e.g.: Groovy, Ruby

def foo() { def a = 42; a = “hello”;}

def foo a = 0 a = “hello”end

Tuesday, January 18, 2011

Misconceptions

Tuesday, January 18, 2011

Statically type checked languages require type

declarations

Tuesday, January 18, 2011

So, what about C#, Scala and ML?

Tuesday, January 18, 2011

All “scripting” languages are dynamically type checked

Tuesday, January 18, 2011

Well, Scala is statically type checked

Tuesday, January 18, 2011

All dynamically type checked languages are not compiled

Tuesday, January 18, 2011

Really? So, what is Groovy?

Tuesday, January 18, 2011

Dynamically type checked languages are weakly typed

Tuesday, January 18, 2011

Wait! Weak?!

Tuesday, January 18, 2011

Strong vs. Weak dilemma

Tuesday, January 18, 2011

Strongly typed languaguesA language that defines a set of rules that restrict values of different types of interacting

Tuesday, January 18, 2011

a = 1b = “1”c = a + bTypeError: String can't be coerced into Fixnum

e.g.: Ruby

Tuesday, January 18, 2011

Weakly typed languaguesA language that does not define a set of rules that restrict values of different types of interacting but

automatically tries to convert somehow one value’s type into the other’s

Tuesday, January 18, 2011

Dynamically type checked languages are weakly typed not

manifest typed

Tuesday, January 18, 2011

a = 1b = “1”c = a + b // 11

e.g.: Javascript

Tuesday, January 18, 2011

Q&A

Tuesday, January 18, 2011

ReferencesBooks

Piece, Benjamin (2002). Types and Programming Languages.Scott, Michael (2009). Programming Language Pragmatics.

Wirth, Niklaus (1996). Compiler Construction.

Web

http://lucacardelli.name/Papers/TypeSystems.pdfhttp://web.archive.org/web/20080822101209/http://www.pphsg.org/cdsmith/types.html

http://web.archive.org/web/20080331215906/perl.plover.com/yak/typing/notes.html http://plato.stanford.edu/entries/type-theory/

http://www.jstor.org/stable/2266170 http://www.cs.cornell.edu/info/projects/nuprl/book/node31.html

http://research.microsoft.com/en-us/um/people/emeijer/Papers/RDL04Meijer.pdfhttp://docs.google.com/View?id=dcsvntt2_25wpjvbbhk

Tuesday, January 18, 2011

Danke :)

Tuesday, January 18, 2011

top related