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 o n g h q . c o m>
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
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
u n t y p e d : n o t 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 o u c a n d o " 1 " + 2 )
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 o n ' t L u a , S c h e me , J a v a S c r i p t , P y t h o n , 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 o , C # , R u s t , H a s k e l l , e t c .
P y t h o n → my p y , p y t y p e R u b y → S o r 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 .
L u a ?
a d d i n g t y p e s ( o r 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 o n c e p t u a l l y - a n d i n i mp l e me n t a t i o n
a d d i n g t y p e s ( o r 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 o n c e p t u a l l y - a n d i n i mp l e me n t a t i o n
a d d i n g t y p e s ( o r 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 o n c e p t u a l l y - a n d i n i mp l e me n t a t i o n
i f t h e l a n g u a g e g r o ws t o o mu c h , i t d o e 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 l a n g u a g e g r o ws t o o mu c h , i t d o e 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 o o s i mp l i s t i c , i t d o e s n ' t f e e l l i k e L u a a n y mo r e
b u t we w a n t b o t h : a s ma l l l a n g u a g e t h a t fj t s i n y o u 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 o u ma k e a s i l l y t y p o
t h e c h a l l e n g e : t o fj n d t h e s we e t s p o t b e t we e n mi n i ma l i s m a n d f u n c t i o n a l i t y
t l
mi n i ma l i mp l e me n t a t i o n 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 o d 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 0 6 l i n e s p u r e L u a , n o d e p e n d e n c i e s
n o d e p e n d e n c i e s : d r o p t l . l u a i n y o u r L u a p r o j e c t a n d o fg y o u g o
tl check file.tl → tl gen file.tl file.lua → tl run file.tl
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 )
function f(x) return x end local z = f(0)
function f(x: number): number return x end local z = f(0)
t l r e p o r t s e r r o r s a n d u n k n o wn s s e p a r a t e l y
t y p e c h e c k e r : t h e b u l k o f t h e c o mp i l e r
function keys(t: {string: string}): {string} local ks = {} for k, v in pairs(t) do table.insert(ks, k) end return ks end
t y p e s o f t a b l e s
wh a t i s a L u a t a b l e ?
t a b l e s i n t l : {string:boolean} ma p s , l i k e {string} a r r a y , l i k e Point r e c o r d , l i k e Node a r r a y - r e c o r d , l i k e a r r a y - ma p ? n o t y e t
t a b l e s i n t l : {string:boolean} ma p s , l i k e {string} a r r a y , l i k e Point r e c o r d , l i k e Node a r r a y - r e c o r d , l i k e a r r a y - ma p ? n o t y e t
t a b l e s i n t l : {string:boolean} ma p s , l i k e {string} a r r a y , l i k e Point r e c o r d , l i k e Node a r r a y - r e c o r d , l i k e a r r a y - ma p ? n o t y e t
t a b l e s i n t l : {string:boolean} ma p s , l i k e {string} a r r a y , l i k e Point r e c o r d , l i k e Node a r r a y - r e c o r d , l i k e a r r a y - ma p ? n o t y e t
t a b l e s i n t l : {string:boolean} ma p s , l i k e {string} a r r a y , l i k e Point r e c o r d , l i k e Node a r r a y - r e c o r d , l i k e a r r a y - ma p ? n o t y e t
t a b l e s i n t l : {string:boolean} ma p s , l i k e {string} a r r a y , l i k e Point r e c o r d , l i k e Node a r r a y - r e c o r d , l i k e a r r a y - ma p ? n o t y e t
n o mi n a l r e c o r d s Point = record x: number y: number end
n o i n h e r i t a n c e o r i n t e r f a c e s / t r a i t s ( f o r n o w? )
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 o wr i t e v e r y g e n e r i c c o d e
function keys(t: {`K: `V}): {`K} local ks = {} for k, v in pairs(t) do table.insert(ks, k) end return ks end
p r i o r i t i z i n g p r a c t i c a l n e e d s o v e r a f e a t u r e c h e c k l i s t
y a y , t y p e s ! n o w wh a t ?
wh i c h e r r o r s a r e l e f t ?
oops.lua:279: attempt to index a nil value (field '?') stack traceback: oops.lua:279: in function 'oh_no' oops.lua:12: in function 'not_again' oops.lua:490: in function 'main' [C]: in ?
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
o p t i o n 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 . . .
t r i c k i e r f o r L u a : t[x] e v e r y r e t u r n s a n o p t i o n t y p e ? n a h
. . . h a v e t h e c o mp i l e r d e t e c t i t ?
d u g o u t o f t h e r a b b i t h o l e !
. . . 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 !
p r a c t i c a l i s s u e s ! i
d e fj n i t i o n fj l e s require("socket") socket.d.tl wh e n t y p e c h e c k i n g , l o a d socket.lua wh e n r u n n i n g , l o a d
L u a h a s n o f u n c t i o n o v e r l o a d i n g ! b u t i t ' s c o mmo n t o f a k e i t
c h a l l e n g e : love.graphics.print( { {1,1,1,1}, "Hello", {1,0,0,1}, " World" } )
coloredtext ? wh a t i s t h e t y p e o f
coloredtext ? wh a t i s t h e t y p e o f any 1 .
coloredtext ? wh a t i s t h e t y p e o f any 1 . table 2 .
coloredtext ? wh a t i s t h e t y p e o f any 1 . table 2 . {any} 3 .
coloredtext ? wh a t i s t h e t y p e o f any 1 . table 2 . {any} 3 . {string or {number}} 4 .
coloredtext ? wh a t i s t h e t y p e o f any 1 . table 2 . {any} 3 . {string or {number}} 4 . {[i%2==1]:{number},[i%2==0]:string} 5 .
coloredtext ? wh a t i s t h e t y p e o f any 1 . table 2 . {any} 3 . {string or {number}} 4 . {[i%2==1]:{number},[i%2==0]:string} 5 . {[i%2==1]:({number}|len==4), 6 . [i%2==0]:string}
Recommend
More recommend