Slide 1

Slide 1 text

Erlang Meets Dependent Types Sam Elliott edλ, 14 July 2015

Slide 2

Slide 2 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Erlang • Actor-based Concurrent Programming Language • !, receive, and spawn • Mailbox per Isolated Process Sam Elliott Erlang Meets Dependent Types

Slide 3

Slide 3 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Erlang Advanced Features • Dynamically Typed • dialyzer • OTP: Behaviours Sam Elliott Erlang Meets Dependent Types

Slide 4

Slide 4 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Dependently-Typed Languages • Idris • Agda • Coq Sam Elliott Erlang Meets Dependent Types

Slide 5

Slide 5 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Idris • Dependently-typed Pure Programming Language • Types are Values • Values are Types • Programs and Proofs Sam Elliott Erlang Meets Dependent Types

Slide 6

Slide 6 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Idris IRs “Cross-platform Compilers for Functional Languages” • Idris • TT • TTcase • IRcase • IRlift • IRdefunc • IRANF • Idris Bytecode Sam Elliott Erlang Meets Dependent Types

Slide 7

Slide 7 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion IRdefunc Sam Elliott Erlang Meets Dependent Types

Slide 8

Slide 8 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Actors data Actor : Type → Type → Type proc : Actor l () Sam Elliott Erlang Meets Dependent Types

Slide 9

Slide 9 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Actors data Actor : Type → Type → Type proc : Actor l () recieve : Actor l l Sam Elliott Erlang Meets Dependent Types

Slide 10

Slide 10 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Actors data Actor : Type → Type → Type proc : Actor l () recieve : Actor l l spawn : (Actor l’ a) → Actor l (ActorID l’) data ActorID : Type → Type pid : ActorID l Sam Elliott Erlang Meets Dependent Types

Slide 11

Slide 11 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Actors data Actor : Type → Type → Type proc : Actor l () recieve : Actor l l spawn : (Actor l’ a) → Actor l (ActorID l’) data ActorID : Type → Type pid : ActorID l send : ActorID l’ → l’ → Actor l () Sam Elliott Erlang Meets Dependent Types

Slide 12

Slide 12 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion RPC data RPCLang : (r : Type) → (r → Type) → Type Sam Elliott Erlang Meets Dependent Types

Slide 13

Slide 13 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion RPC data RPCLang : (r : Type) → (r → Type) → Type data LockReq = Lock | Unlock data LockLockResp = Grant | Wait total LockResp : LockReq → Type LockResp Lock = LockLockResp LockResp Unlock = Unit LockLang : RPCLang LockReq LockResp Sam Elliott Erlang Meets Dependent Types

Slide 14

Slide 14 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion RPC II data RPCRef : RPCLang rq rs → Type rpc : {l : RPCLang rq rs} → RPCRef l → (m : rq) → EIO (rs m) Sam Elliott Erlang Meets Dependent Types

Slide 15

Slide 15 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion RPC II data RPCRef : RPCLang rq rs → Type rpc : {l : RPCLang rq rs} → RPCRef l → (m : rq) → EIO (rs m) pid : RPCRef LockLang rpc pid Lock : LockLockResp rpc pid Unlock : Unit Sam Elliott Erlang Meets Dependent Types

Slide 16

Slide 16 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion RPC III spawn : {l : RPCLang rq rs} → (r : rq → rs r) → EIO (RPCRef l) Sam Elliott Erlang Meets Dependent Types

Slide 17

Slide 17 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion RPC III spawn : {l : RPCLang rq rs} → (r : rq → rs r) → EIO (RPCRef l) total lock : (m : LockReq) → LockResp m lock Lock = Grant -- Oh Crap! lock Unlock = () Sam Elliott Erlang Meets Dependent Types

Slide 18

Slide 18 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion RPC III spawn : {l : RPCLang rq rs} → (r : rq → rs r) → EIO (RPCRef l) total lock : (m : LockReq) → LockResp m lock Lock = Grant -- Oh Crap! lock Unlock = () State? Side Effects? Sam Elliott Erlang Meets Dependent Types

Slide 19

Slide 19 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion OTP • “Open Telecoms Platform” • Lots of great defaults • Generic Behaviours! • Supervisors! Sam Elliott Erlang Meets Dependent Types

Slide 20

Slide 20 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Generic Behaviours • gen server • gen fsm • gen event Sam Elliott Erlang Meets Dependent Types

Slide 21

Slide 21 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion gen server data GSL : (cl : Type) → (cl → Type) → Type → Type data GSRef : GSL cl cr ct → Type Sam Elliott Erlang Meets Dependent Types

Slide 22

Slide 22 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion gen server data GSL : (cl : Type) → (cl → Type) → Type → Type data GSRef : GSL cl cr ct → Type call : {l : GSL cl cr ct} → GSRef l → (m : cl) → EIO (cr m) cast : {l : GSL cl cr ct} → GSRef l → ct → EIO Unit Sam Elliott Erlang Meets Dependent Types

Slide 23

Slide 23 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion gen server data GS : (GSL cl cr ct) → Type → Type → Type spawn : (GS l st i) → i → EIO (GSRef i) Sam Elliott Erlang Meets Dependent Types

Slide 24

Slide 24 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Conclusion • We can produce verified concurrent programs in Idris • We can compile these programs to work with Erlang • We can run verified programs in Erlang Sam Elliott Erlang Meets Dependent Types

Slide 25

Slide 25 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Read More Sam Elliott Erlang Meets Dependent Types

Slide 26

Slide 26 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Thanks To Edwin Brady Rob Stewart Skyscanner & Mike Moran Sam Elliott Erlang Meets Dependent Types

Slide 27

Slide 27 text

Erlang Dependent Types Compiler Concurrency OTP Conclusion Any Questions? Sam Elliott Erlang Meets Dependent Types