Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Erlang Meets Dependent Types

Erlang Meets Dependent Types

Talk given at EdLambda, in July 2015.

Dissertation Link: http://lenary.co.uk/publications/dissertation/

Sam Elliott

July 14, 2015
Tweet

More Decks by Sam Elliott

Other Decks in Research

Transcript

  1. 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
  2. Erlang Dependent Types Compiler Concurrency OTP Conclusion Erlang Advanced Features

    • Dynamically Typed • dialyzer • OTP: Behaviours Sam Elliott Erlang Meets Dependent Types
  3. Erlang Dependent Types Compiler Concurrency OTP Conclusion Dependently-Typed Languages •

    Idris • Agda • Coq Sam Elliott Erlang Meets Dependent Types
  4. 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
  5. 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
  6. Erlang Dependent Types Compiler Concurrency OTP Conclusion Actors data Actor

    : Type → Type → Type proc : Actor l () Sam Elliott Erlang Meets Dependent Types
  7. 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
  8. 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
  9. 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
  10. Erlang Dependent Types Compiler Concurrency OTP Conclusion RPC data RPCLang

    : (r : Type) → (r → Type) → Type Sam Elliott Erlang Meets Dependent Types
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. Erlang Dependent Types Compiler Concurrency OTP Conclusion OTP • “Open

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

    gen server • gen fsm • gen event Sam Elliott Erlang Meets Dependent Types
  19. 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
  20. 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
  21. 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
  22. 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
  23. Erlang Dependent Types Compiler Concurrency OTP Conclusion Thanks To Edwin

    Brady Rob Stewart Skyscanner & Mike Moran Sam Elliott Erlang Meets Dependent Types