hisham muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · lua, scheme, erlang, python, ruby,...

67
minimalism versus types Hisham Muhammad <[email protected]>

Upload: others

Post on 01-Oct-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

minimalism versus typesHisham Muhammad<[email protected]>

Page 2: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

minimalismLua: fits in my head

Page 3: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

g

Page 4: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

typespair-programming with the computer

Page 5: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

untyped: no types at allassembly, un(i)typed lambda calculus

typed: types exist!string and number are different things

(even if you can do "1" + 2)

Page 6: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

dynamically typed:values have types, variables don't

Lua, Scheme, Erlang, Python, Ruby, PHP, etc.

statically typed:values have types, variables have types

C, Java, Go, C#, Rust, Haskell, etc.

Page 7: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

strongly typedweakly typed

Page 8: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

dynamically typed:values have types, variables don't

Lua, Scheme, Erlang, Python, Ruby, PHP, etc.

statically typed:values have types, variables have types

C, Java, Go, C#, Rust, Haskell, etc.

Page 9: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

what happens when we putminimalism and types together?

Page 10: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

a brief history of typing Lua

Page 11: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

2013: Tidal Lockhttps://github.com/fab13n/metalua/blob/tilo/src/tilo/readme.md

Page 12: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

2015: Typed Luahttps://github.com/andremm/typedlua

Page 13: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

2017: Titanhttps://github.com/titan-lang/titan

Page 14: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

2018: Pallenehttps://github.com/pallene-lang/pallene

Page 15: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

and yet

Page 16: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

why is it so hard?

Page 17: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

once you add types and the whole enchilada that comes with it, then the language is

no longer minimalistic,right?

Page 18: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

once you add types and the whole enchilada that comes with it, then the language is

no longer minimalistic,right?

types make our tiny languages complicated?

Page 19: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

the problem is kinda the opposite

Page 20: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

dynamically typed languageshave HUGE type systems

Page 21: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

type system: set of rules that describewhat are the valid interactions of values

in correct programs

Page 22: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

type system: set of rules that describewhat are the valid interactions of values

in correct programsit's in your head!

Page 23: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

you are the type checker

Page 24: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

obj.x, obj.y = get_coords()

can't do that:yesterday I changed get_coords from

return x, yto return { x = x, y = y }

Page 25: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

what are the rules in your head?

Page 26: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

dynamically typed:values have types, variables don't

Lua, Scheme, Erlang, Python, Ruby, PHP, etc.

statically typed:values have types, variables have types

C, Java, Go, C#, Rust, Haskell, etc.

dependently typed:values have types, variables have types...

and types have values! and types!Idris, Agda... not that many yet!

Page 27: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

function f(a, b)

Page 28: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

function f(a, b)

a: integerb: if a < 256 then string else array of strings

Page 29: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

function f(a, b)

a: integerb: if a < 256 then string else array of strings

red: integergreen: integerblue: integer

Page 30: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

function f(a, b)

a: integerb: if a < 256 then string else array of strings

red: integergreen: integerblue: integer

f(red, {1, 2, 3})

Page 31: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

Curry-Howard correspondencepropositions ↔ typeslogic ↔ type system

Page 32: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

btw, arithmetics is undecidable

Page 33: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

local t = {} local ok, err = load_values_into_table(t) if not ok then return nil, "failed! " .. err end return { r = t[1], g = t[2], b = t[3] }

Page 34: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

Lua: table is the only structured type

Page 35: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

everything is a tablea table is anything

Page 36: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

everything is a tablea table is anything

an array

Page 37: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

everything is a tablea table is anything

an arraya dictionary

Page 38: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

everything is a tablea table is anything

an arraya dictionary

a struct

Page 39: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

everything is a tablea table is anything

an arraya dictionary

a structan object

Page 40: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

everything is a tablea table is anything

an arraya dictionary

a structan object

a dictionary mapping objects to strings or arrays depending on whether field x of the

key object is true or false

Page 41: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

expressiveness

Page 42: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

not really what a language can expressbut how can you express it

Page 43: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

dynamically typed languages aresuper expressive

like a blank sheet of paper

Page 44: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

type checker works both for good("Thank you for catching my silly typo!")

and bad("no, I _know_ that this use of the variable is safe!")

Page 45: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

expressiveness is the feel of a language

Page 46: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

local t = {} t.name = "items" t[1] = 100 t[2] = 200

Page 47: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

here's the dilemma:how much of the language do you change?

Page 48: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

if you want to make it feel like Lua,then the type checker is super complexif you want to finish your type checker,

you have to make cuts somewher

Page 49: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

two options on where to make cuts

Page 50: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

cut on programmer expressiveness{ name = "items", items = {100, 200} }

return x, y and return nil, errvs.

return x, y and return nil, nil, err

Page 51: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

cut on the correctness of the type checker

Page 52: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

"every program the type checker accepts has correct types"

"every program that the type checker rejects has wrong types"

Page 53: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

the more sophisticated your type system,the deeper you are in research territory

Page 54: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

soundness vs. usability (vs. performance!)Typed Lua

Typed ClojureTyped Racket

Page 55: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

is all lost?

Page 56: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

TypeScript

Page 57: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

usability above all elsehttps://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals

Page 58: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

intentionally unsound

Page 59: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

intentionally unsound

Page 60: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

what about Lua?

Page 61: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

exploring this design space

tl: minimalistic Lua type checkerwhat's the minimum set of features

so that it can check itself?

Page 62: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

tl tl.tl: currently fails with 384 type errors

Page 63: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

tl tl.tl: currently fails with 384 type errors(one week ago it was 1493!)

Page 64: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

TypeScript: JavaScript-like(features, features, features!)

tl: aiming for Lua-like(a balance between functionality and small size)

Page 65: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

http://github.com/hishamhm/tl

Page 66: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

so, in closing

Page 67: Hisham Muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · Lua, Scheme, Erlang, Python, Ruby, PHP, etc. statically typed: values have types, variables have types C, Java, Go,

Lua and types: to be continued!

thank you