mi n i ma l i s t i c t y p e d L u a i s h e r - - PowerPoint PPT Presentation

mi n i ma l i s t i c t y p e d l u a i s h e r e
SMART_READER_LITE
LIVE PREVIEW

mi n i ma l i s t i c t y p e d L u a i s h e r - - PowerPoint PPT Presentation

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


slide-1
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

  • n

g h q . c

  • m>
slide-2
SLIDE 2
slide-3
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
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
SLIDE 5

u n t y p e d : n

  • 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

  • u

c a n d

  • "

1 " + 2 )

slide-6
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

  • n

' t

L u a , S c h e me , J a v a S c r i p t , P y t h

  • 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

  • ,

C # , R u s t , H a s k e l l , e t c .

slide-7
SLIDE 7

P y t h

  • n

→ my p y , p y t y p e R u b y → S

  • 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 .

slide-8
SLIDE 8

L u a ?

slide-9
SLIDE 9

a d d i n g t y p e s (

  • 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
  • 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

  • n
slide-10
SLIDE 10

a d d i n g t y p e s (

  • 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
  • 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

  • n
slide-11
SLIDE 11

a d d i n g t y p e s (

  • 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
  • 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

  • n
slide-12
SLIDE 12

i f t h e l a n g u a g e g r

  • ws

t

  • mu

c h , i t d

  • e

s n ' t f e e l l i k e L u a a n y mo r e

slide-13
SLIDE 13

i f t h e l a n g u a g e g r

  • ws

t

  • mu

c h , i t d

  • 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

  • s

i mp l i s t i c , i t d

  • e

s n ' t f e e l l i k e L u a a n y mo r e

slide-14
SLIDE 14

b u t we w a n t b

  • 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

  • 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

  • u

ma k e a s i l l y t y p

slide-15
SLIDE 15

t h e c h a l l e n g e : t

  • fj

n d t h e s we e t s p

  • t

b e t we e n mi n i ma l i s m a n d f u n c t i

  • n

a l i t y

slide-16
SLIDE 16

t l

slide-17
SLIDE 17

mi n i ma l i mp l e me n t a t i

  • 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

  • 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 6 l i n e s p u r e L u a , n

  • d

e p e n d e n c i e s

slide-18
SLIDE 18
slide-19
SLIDE 19

n

  • d

e p e n d e n c i e s : d r

  • p

t l . l u a i n y

  • u

r L u a p r

  • j

e c t a n d

  • fg

y

  • u

g

slide-20
SLIDE 20

tl check file.tl → tl gen file.tl → file.lua tl run file.tl

slide-21
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
SLIDE 22

function f(x) return x end local z = f(0)

slide-23
SLIDE 23

function f(x: number): number return x end local z = f(0)

slide-24
SLIDE 24

t l r e p

  • r

t s e r r

  • r

s a n d u n k n

  • wn

s s e p a r a t e l y

slide-25
SLIDE 25

t y p e c h e c k e r : t h e b u l k

  • f

t h e c

  • mp

i l e r

slide-26
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
SLIDE 27

t y p e s

  • f

t a b l e s

slide-28
SLIDE 28

wh a t i s a L u a t a b l e ?

slide-29
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

  • r

d , l i k e Point a r r a y

  • r

e c

  • r

d , l i k e Node a r r a y

  • ma

p ? n

  • t

y e t

slide-30
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

  • r

d , l i k e Point a r r a y

  • r

e c

  • r

d , l i k e Node a r r a y

  • ma

p ? n

  • t

y e t

slide-31
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

  • r

d , l i k e Point a r r a y

  • r

e c

  • r

d , l i k e Node a r r a y

  • ma

p ? n

  • t

y e t

slide-32
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

  • r

d , l i k e Point a r r a y

  • r

e c

  • r

d , l i k e Node a r r a y

  • ma

p ? n

  • t

y e t

slide-33
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

  • r

d , l i k e Point a r r a y

  • r

e c

  • r

d , l i k e Node a r r a y

  • ma

p ? n

  • t

y e t

slide-34
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

  • r

d , l i k e Point a r r a y

  • r

e c

  • r

d , l i k e Node a r r a y

  • ma

p ? n

  • t

y e t

slide-35
SLIDE 35

n

  • mi

n a l r e c

  • r

d s Point = record x: number

y: number

end

slide-36
SLIDE 36

n

  • i

n h e r i t a n c e

  • r

i n t e r f a c e s / t r a i t s ( f

  • r

n

  • w?

)

slide-37
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

  • wr

i t e v e r y g e n e r i c c

  • d

e

slide-38
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
SLIDE 39

p r i

  • r

i t i z i n g p r a c t i c a l n e e d s

  • v

e r a f e a t u r e c h e c k l i s t

slide-40
SLIDE 40

y a y , t y p e s ! n

  • w

wh a t ?

slide-41
SLIDE 41

wh i c h e r r

  • r

s a r e l e f t ?

slide-42
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
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
SLIDE 44
  • p

t i

  • 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 . . .

slide-45
SLIDE 45

t r i c k i e r f

  • r

L u a : e v e r y t[x] r e t u r n s a n

  • p

t i

  • n

t y p e ? n a h

slide-46
SLIDE 46

. . . h a v e t h e c

  • mp

i l e r d e t e c t i t ?

slide-47
SLIDE 47
slide-48
SLIDE 48
slide-49
SLIDE 49

d u g

  • u

t

  • f

t h e r a b b i t h

  • l

e !

slide-50
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
SLIDE 51

i

p r a c t i c a l i s s u e s !

slide-52
SLIDE 52
slide-53
SLIDE 53

d e fj n i t i

  • n

fj l e s require("socket") wh e n t y p e c h e c k i n g , l

  • a

d socket.d.tl wh e n r u n n i n g , l

  • a

d socket.lua

slide-54
SLIDE 54
slide-55
SLIDE 55

L u a h a s n

  • f

u n c t i

  • n
  • v

e r l

  • a

d i n g ! b u t i t ' s c

  • mmo

n t

  • f

a k e i t

slide-56
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 57
slide-58
SLIDE 58

wh a t i s t h e t y p e

  • f

coloredtext?

slide-59
SLIDE 59

wh a t i s t h e t y p e

  • f

coloredtext? 1 . any

slide-60
SLIDE 60

wh a t i s t h e t y p e

  • f

coloredtext? 1 . any 2 . table

slide-61
SLIDE 61

wh a t i s t h e t y p e

  • f

coloredtext? 1 . any 2 . table 3 . {any}

slide-62
SLIDE 62

wh a t i s t h e t y p e

  • f

coloredtext? 1 . any 2 . table 3 . {any} 4 . {string or {number}}

slide-63
SLIDE 63

wh a t i s t h e t y p e

  • f

coloredtext? 1 . any 2 . table 3 . {any} 4 . {string or {number}} 5 . {[i%2==1]:{number},[i%2==0]:string}

slide-64
SLIDE 64

wh a t i s t h e t y p e

  • f

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
SLIDE 65

wh a t i s t h e t y p e

  • f

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
SLIDE 66

wh a t i s t h e t y p e

  • f

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
SLIDE 67

wh a t i s t h e t y p e

  • f

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
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
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

  • ma

i n t a i n a n a p p l i c a t i

  • n

?

slide-70
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

  • ma

i n t a i n a n a p p l i c a t i

  • n

? Y E S !

slide-71
SLIDE 71

s

  • ,

i n c l

  • s

i n g

slide-72
SLIDE 72

h t t p : / / g i t h u b . c

  • m/

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

  • k

i n g f

  • r

a b e t t e r n a me ! )

slide-73
SLIDE 73

L u a a n d t y p e s : j

  • i

n u s ! t h a n k y

  • u