hisham muhammadhisham.hm/papers/talks/minimalism-vs-types.pdf · lua, scheme, erlang, python, ruby,...
TRANSCRIPT
minimalism versus typesHisham Muhammad<[email protected]>
minimalismLua: fits in my head
g
typespair-programming with the computer
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)
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.
strongly typedweakly typed
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.
what happens when we putminimalism and types together?
a brief history of typing Lua
2013: Tidal Lockhttps://github.com/fab13n/metalua/blob/tilo/src/tilo/readme.md
2015: Typed Luahttps://github.com/andremm/typedlua
2017: Titanhttps://github.com/titan-lang/titan
2018: Pallenehttps://github.com/pallene-lang/pallene
and yet
why is it so hard?
once you add types and the whole enchilada that comes with it, then the language is
no longer minimalistic,right?
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?
the problem is kinda the opposite
dynamically typed languageshave HUGE type systems
type system: set of rules that describewhat are the valid interactions of values
in correct programs
type system: set of rules that describewhat are the valid interactions of values
in correct programsit's in your head!
you are the type checker
obj.x, obj.y = get_coords()
can't do that:yesterday I changed get_coords from
return x, yto return { x = x, y = y }
what are the rules in your head?
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!
function f(a, b)
function f(a, b)
a: integerb: if a < 256 then string else array of strings
function f(a, b)
a: integerb: if a < 256 then string else array of strings
red: integergreen: integerblue: integer
function f(a, b)
a: integerb: if a < 256 then string else array of strings
red: integergreen: integerblue: integer
f(red, {1, 2, 3})
Curry-Howard correspondencepropositions ↔ typeslogic ↔ type system
btw, arithmetics is undecidable
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] }
Lua: table is the only structured type
everything is a tablea table is anything
everything is a tablea table is anything
an array
everything is a tablea table is anything
an arraya dictionary
everything is a tablea table is anything
an arraya dictionary
a struct
everything is a tablea table is anything
an arraya dictionary
a structan object
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
expressiveness
not really what a language can expressbut how can you express it
dynamically typed languages aresuper expressive
like a blank sheet of paper
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!")
expressiveness is the feel of a language
local t = {} t.name = "items" t[1] = 100 t[2] = 200
here's the dilemma:how much of the language do you change?
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
two options on where to make cuts
cut on programmer expressiveness{ name = "items", items = {100, 200} }
return x, y and return nil, errvs.
return x, y and return nil, nil, err
cut on the correctness of the type checker
"every program the type checker accepts has correct types"
"every program that the type checker rejects has wrong types"
the more sophisticated your type system,the deeper you are in research territory
soundness vs. usability (vs. performance!)Typed Lua
Typed ClojureTyped Racket
is all lost?
TypeScript
usability above all elsehttps://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
intentionally unsound
intentionally unsound
what about Lua?
exploring this design space
tl: minimalistic Lua type checkerwhat's the minimum set of features
so that it can check itself?
tl tl.tl: currently fails with 384 type errors
tl tl.tl: currently fails with 384 type errors(one week ago it was 1493!)
TypeScript: JavaScript-like(features, features, features!)
tl: aiming for Lua-like(a balance between functionality and small size)
http://github.com/hishamhm/tl
so, in closing
Lua and types: to be continued!
thank you