Software Testing: Test Design Iain McCowatt [email protected] @imccowatt imccowatt.
E cient linear types for human beings Iain Lane
Transcript of E cient linear types for human beings Iain Lane
![Page 1: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/1.jpg)
Linear MLEfficient linear types for human beings
Iain Lane
School of Computer ScienceUniversity of Nottingham
9 July, 2011
![Page 2: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/2.jpg)
Outline
Introduction
Linear logic
Linear ML
Demo!
Fin
![Page 3: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/3.jpg)
Introduction
I Internship at the beginning of the year (January–April)
I Funded by Horizon project (www.horizon.ac.uk)
![Page 4: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/4.jpg)
Project
I Work on a new programming language: Linear MLI Got some coverage on the internets
I Reddit(http://www.reddit.com/r/types/comments/g118j/linearml_is_a_pogramming_language_designed_to/)
I Ycombinator(http://news.ycombinator.com/item?id=2310587)
![Page 5: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/5.jpg)
This talk
I Introduction to linear logic & linear type systems
I Introduction to Linear ML
I Demo, if time
![Page 6: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/6.jpg)
Outline
Introduction
Linear logic
Linear ML
Demo!
Fin
![Page 7: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/7.jpg)
WTF?
I First proposed by Girard in 1987 (Girard is also the inventor ofthe mustard watch)
I The connectives of linear logic have meanings in terms ofparallel and concurrent computation
I Traditional logic encourages casual use of assumptions.Duplication is free. In linear logic it is restricted via alterationsto the weakening and contraction rules
I Beginning to be used in OS research: Microsoft “Singularity”project uses linear typing for message passing
![Page 8: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/8.jpg)
Linear logicNew connectives
I N “choose from A and B”
I ⊕ “either A or B”
I A⊗ B “both A and B”
I A ( B “A linearly implies B” or “consuming A yields B”
I !A “bang A”
![Page 9: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/9.jpg)
Variables
Two kinds of variables
I Linear: ¿A
I Nonlinear (or sometimes “intuitionistic”): ?A
![Page 10: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/10.jpg)
Some inference rules
both
∆ ` A ∆′ ` B
∆,∆′ ` A⊗ B⊗I
∆ ` A⊗ B ∆′, ¿A, ¿B ` C
∆,∆′ ` C⊗E
choose
∆ ` A ∆ ` B
∆ ` A N BNI
∆ ` A N B
∆ ` ANE1
∆ ` A N B
∆ ` BNE2
![Page 11: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/11.jpg)
either
∆ ` A
∆ ` A⊕ B⊕I1
∆ ` B
∆ ` A⊕ B⊕I2
wand
∆, ¿A ` B
∆ ` A ( B( I
![Page 12: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/12.jpg)
structural
∆ ` B
∆, ?A ` BWeakening
∆, ?A, ?A ` B
∆, ?A ` BContraction
bang
?∆ ` A
?∆ `!A!I
∆ `!A ∆′, ?A ` B
∆,∆′ ` B!E
![Page 13: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/13.jpg)
ExampleA packet-response system
Given three types: Packet, Response and Command.
A packet can either elicit a response or issue a command
¿Packet ` Response ¿Packet ` Command
![Page 14: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/14.jpg)
Given two distinct packets, we can produce both a responseand a command
¿Packet, ¿Packet ` Response⊗ Command
Given one packet, the server can decide whether to send aresponse or elicit a command
¿Packet ` Response N Command
![Page 15: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/15.jpg)
Linear types?
I Variables must be used exactly once
I Enforced by going out of scope after they are used
I Useful for expressing ownership
![Page 16: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/16.jpg)
Example
The code
w r i t e ‘ ‘ E n t e r your name : ’ ’s t r i n g name = r e a d L i n ew r i t e L i n e ( s p r i n t f ” H e l l o %s ” name )
Works just as you’d expect.
![Page 17: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/17.jpg)
Example
BUT, the code
w r i t e ‘ ‘ E n t e r your name : ’ ’s t r i n g name = r e a d L i n ew r i t e L i n e ( s p r i n t f ” H e l l o %s ” name )w r i t e F i l e ‘ ‘ e . v . l . h a c k e r s . log ’ ’ name
Fails. Line 4: Variable ’name’ not in scope. name was consumedby the first writeLine.
![Page 18: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/18.jpg)
Outline
Introduction
Linear logic
Linear ML
Demo!
Fin
![Page 19: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/19.jpg)
Linear ML
I Linearly typed ‘dialect’ of ML (uses OCaml-like syntax)
I Compiled to LLVM
I Statically typed
I Strict evaluation order
![Page 20: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/20.jpg)
Linear MLLinear types imply
I Messages passed between threads without copying
I Majority of operations performed in-place
I No need for GC
![Page 21: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/21.jpg)
Outline
Introduction
Linear logic
Linear ML
Demo!
Fin
![Page 22: E cient linear types for human beings Iain Lane](https://reader033.fdocuments.us/reader033/viewer/2022042723/6267d3d9fb97924ab971d4e2/html5/thumbnails/22.jpg)
Outline
Introduction
Linear logic
Linear ML
Demo!
Fin