SLIDE 1 mi n i ma l i s t i c t y p e d L u a i s h e r e
H i s h a m Mu h a mma d
< h i s h a m@k
g h q . c
SLIDE 2
SLIDE 3
mi n i ma l i s t i c e x p e r i me n t a l e me r g i n g
SLIDE 4
mi n i ma l i s t i c e x p e r i me n t a l e me r g i n g
SLIDE 5 u n t y p e d : n
y p e s a t a l l
a s s e mb l y , u n ( i ) t y p e d l a mb d a c a l c u l u s
t y p e d : t y p e s e x i s t !
s t r i n g a n d n u mb e r a r e d i fg e r e n t t h i n g s
( e v e n i f y
c a n d
1 " + 2 )
SLIDE 6 d y n a mi c a l l y t y p e d : v a l u e s h a v e t y p e s , v a r i a b l e s d
' t
L u a , S c h e me , J a v a S c r i p t , P y t h
, R u b y , P H P , e t c .
s t a t i c a l l y t y p e d : v a l u e s h a v e t y p e s , v a r i a b l e s h a v e t y p e s
C , J a v a , G
C # , R u s t , H a s k e l l , e t c .
SLIDE 7 P y t h
→ my p y , p y t y p e R u b y → S
b e t P H P → H a c k J a v a S c r i p t → T y p e S c r i p t R a c k e t → T y p e d R a c k e t e t c .
SLIDE 8
L u a ?
SLIDE 9 a d d i n g t y p e s (
a n y t h i n g ! ) ma k e s a l a n g u a g e l a r g e r
c e p t u a l l y
n d i n i mp l e me n t a t i
SLIDE 10 a d d i n g t y p e s (
a n y t h i n g ! ) ma k e s a l a n g u a g e l a r g e r
c e p t u a l l y
n d i n i mp l e me n t a t i
SLIDE 11 a d d i n g t y p e s (
a n y t h i n g ! ) ma k e s a l a n g u a g e l a r g e r
c e p t u a l l y
n d i n i mp l e me n t a t i
SLIDE 12 i f t h e l a n g u a g e g r
t
c h , i t d
s n ' t f e e l l i k e L u a a n y mo r e
SLIDE 13 i f t h e l a n g u a g e g r
t
c h , i t d
s n ' t f e e l l i k e L u a a n y mo r e i f t h e t y p e c h e c k e r i s t
i mp l i s t i c , i t d
s n ' t f e e l l i k e L u a a n y mo r e
SLIDE 14 b u t we w a n t b
h :
a s ma l l l a n g u a g e t h a t fj t s i n y
r h e a d a t y p e c h e c k e r t h a t c a t c h e s wh e n y
ma k e a s i l l y t y p
SLIDE 15 t h e c h a l l e n g e : t
n d t h e s we e t s p
b e t we e n mi n i ma l i s m a n d f u n c t i
a l i t y
SLIDE 16
t l
SLIDE 17 mi n i ma l i mp l e me n t a t i
i n t h e L u a s p i r i t : L u a : 2 9 7 k B t a r b a l l p u r e s t a n d a r d C , n
e p e n d e n c i e s t l : s i n g l e fj l e , c u r r e n t l y 4 8 6 l i n e s p u r e L u a , n
e p e n d e n c i e s
SLIDE 18
SLIDE 19 n
e p e n d e n c i e s : d r
t l . l u a i n y
r L u a p r
e c t a n d
y
g
SLIDE 20
tl check file.tl → tl gen file.tl → file.lua tl run file.tl
SLIDE 21
t wo mo d e s : . t l ( " s t r i c t " mo d e ) . l u a ( " l a x " mo d e )
SLIDE 22
function f(x) return x end local z = f(0)
SLIDE 23
function f(x: number): number return x end local z = f(0)
SLIDE 24 t l r e p
t s e r r
s a n d u n k n
s s e p a r a t e l y
SLIDE 25 t y p e c h e c k e r : t h e b u l k
t h e c
i l e r
SLIDE 26
function keys(t: {string: string}): {string} local ks = {} for k, v in pairs(t) do table.insert(ks, k) end return ks end
SLIDE 27 t y p e s
t a b l e s
SLIDE 28
wh a t i s a L u a t a b l e ?
SLIDE 29 t a b l e s i n t l : ma p s , l i k e {string:boolean} a r r a y , l i k e {string} r e c
d , l i k e Point a r r a y
e c
d , l i k e Node a r r a y
p ? n
y e t
SLIDE 30 t a b l e s i n t l : ma p s , l i k e {string:boolean} a r r a y , l i k e {string} r e c
d , l i k e Point a r r a y
e c
d , l i k e Node a r r a y
p ? n
y e t
SLIDE 31 t a b l e s i n t l : ma p s , l i k e {string:boolean} a r r a y , l i k e {string} r e c
d , l i k e Point a r r a y
e c
d , l i k e Node a r r a y
p ? n
y e t
SLIDE 32 t a b l e s i n t l : ma p s , l i k e {string:boolean} a r r a y , l i k e {string} r e c
d , l i k e Point a r r a y
e c
d , l i k e Node a r r a y
p ? n
y e t
SLIDE 33 t a b l e s i n t l : ma p s , l i k e {string:boolean} a r r a y , l i k e {string} r e c
d , l i k e Point a r r a y
e c
d , l i k e Node a r r a y
p ? n
y e t
SLIDE 34 t a b l e s i n t l : ma p s , l i k e {string:boolean} a r r a y , l i k e {string} r e c
d , l i k e Point a r r a y
e c
d , l i k e Node a r r a y
p ? n
y e t
SLIDE 35 n
n a l r e c
d s Point = record x: number
y: number
end
SLIDE 36 n
n h e r i t a n c e
i n t e r f a c e s / t r a i t s ( f
n
)
SLIDE 37 wi t h d y n a mi c t y p e s , i t ' s t r i v i a l t
i t e v e r y g e n e r i c c
e
SLIDE 38
function keys(t: {`K: `V}): {`K} local ks = {} for k, v in pairs(t) do table.insert(ks, k) end return ks end
SLIDE 39 p r i
i t i z i n g p r a c t i c a l n e e d s
e r a f e a t u r e c h e c k l i s t
SLIDE 40 y a y , t y p e s ! n
wh a t ?
SLIDE 41 wh i c h e r r
s a r e l e f t ?
SLIDE 42
- ops.lua:279: attempt to index a nil value (field '?')
stack traceback:
- ops.lua:279: in function 'oh_no'
- ops.lua:12: in function 'not_again'
- ops.lua:490: in function 'main'
[C]: in ?
SLIDE 43
t l ( a n d L u a ) : a n y v a r i a b l e ma y b e n i l
SLIDE 44
t i
t y p e s ? Maybe i n H a s k e l l , Result i n R u s t , e t c . . .
SLIDE 45 t r i c k i e r f
L u a : e v e r y t[x] r e t u r n s a n
t i
t y p e ? n a h
SLIDE 46 . . . h a v e t h e c
i l e r d e t e c t i t ?
SLIDE 47
SLIDE 48
SLIDE 49 d u g
t
t h e r a b b i t h
e !
SLIDE 50
. . . b y t h e F O S D E M d e a d l i n e a n d b y u s e r f e e d b a c k !
SLIDE 51
i
p r a c t i c a l i s s u e s !
SLIDE 52
SLIDE 53 d e fj n i t i
fj l e s require("socket") wh e n t y p e c h e c k i n g , l
d socket.d.tl wh e n r u n n i n g , l
d socket.lua
SLIDE 54
SLIDE 55 L u a h a s n
u n c t i
e r l
d i n g ! b u t i t ' s c
n t
a k e i t
SLIDE 56
c h a l l e n g e :
love.graphics.print({{1,1,1,1}, "Hello", {1,0,0,1}, " World"})
SLIDE 57
SLIDE 58 wh a t i s t h e t y p e
coloredtext?
SLIDE 59 wh a t i s t h e t y p e
coloredtext? 1 . any
SLIDE 60 wh a t i s t h e t y p e
coloredtext? 1 . any 2 . table
SLIDE 61 wh a t i s t h e t y p e
coloredtext? 1 . any 2 . table 3 . {any}
SLIDE 62 wh a t i s t h e t y p e
coloredtext? 1 . any 2 . table 3 . {any} 4 . {string or {number}}
SLIDE 63 wh a t i s t h e t y p e
coloredtext? 1 . any 2 . table 3 . {any} 4 . {string or {number}} 5 . {[i%2==1]:{number},[i%2==0]:string}
SLIDE 64 wh a t i s t h e t y p e
coloredtext? 1 . any 2 . table 3 . {any} 4 . {string or {number}} 5 . {[i%2==1]:{number},[i%2==0]:string} 6 . {[i%2==1]:({number}|len==4), [i%2==0]:string}
SLIDE 65 wh a t i s t h e t y p e
coloredtext? 1 . any 2 . table 3 . {any} 4 . {string or {number}} 5 . {[i%2==1]:{number},[i%2==0]:string} 6 . {[i%2==1]:({number}|len==4), [i%2==0]:string} 7 . ({[i%2==1]:({number}|len==4), [i%2==0]:string}|len%2==0)
SLIDE 66 wh a t i s t h e t y p e
coloredtext? 1 . any 2 . table 3 . {any} 4 . {string or {number}} 5 . {[i%2==1]:{number},[i%2==0]:string} 6 . {[i%2==1]:({number}|len==4), [i%2==0]:string} 7 . ({[i%2==1]:({number}|len==4), [i%2==0]:string}|len%2==0) 8 . ({[i%2==1]:({[0-1]}|len==4), [i%2==0]:string}|len%2==0)
SLIDE 67 wh a t i s t h e t y p e
coloredtext? 1 . any 2 . table 3 . {any} 4 . {string or {number}} 5 . {[i%2==1]:{number},[i%2==0]:string} 6 . {[i%2==1]:({number}|len==4), [i%2==0]:string} 7 . ({[i%2==1]:({number}|len==4), [i%2==0]:string}|len%2==0) 8 . ({[i%2==1]:({[0-1]}|len==4), [i%2==0]:string}|len%2==0)
SLIDE 68 local ColorText = record r: number g: number b: number a: number text: string end function my_typed_print(colortext: {ColorText})
end my_typed_print({ {r = 1, g = 1, b = 1, a = 1, text = "Hello"}, {r = 1, g = 0, b = 0, a = 0, text = " World"} })
SLIDE 69 t y p e s i n L u a — d i d t h e y d e l i v e r ? i s i t e a s i e r t
i n t a i n a n a p p l i c a t i
?
SLIDE 70 t y p e s i n L u a — d i d t h e y d e l i v e r ? i s i t e a s i e r t
i n t a i n a n a p p l i c a t i
? Y E S !
SLIDE 72 h t t p : / / g i t h u b . c
h i s h a mh m/ t l r e l e a s e . 1 . luarocks install tl ( s t i l l l
i n g f
a b e t t e r n a me ! )
SLIDE 73 L u a a n d t y p e s : j
n u s ! t h a n k y