Slide 1

Slide 1 text

DEPENDENT TYPES, NOT JUST FOR VECTORS? FP-SYD 2017

Slide 2

Slide 2 text

WHO AM I? ▸ Tim McGilchrist @lambda_foo ▸ Haskell programmer at Ambiata ▸ Curious about Distributed Systems ▸ Curious about Types

Slide 3

Slide 3 text

BACKGROUND HOW DID I GET HERE?

Slide 4

Slide 4 text

ACTORS AND ERLANG Mailbox Process

Slide 5

Slide 5 text

SESSION TYPES ▸ Describe communication protocols ▸ Session types codify the structure of communication ▸ Data types codify the structures communicated

Slide 6

Slide 6 text

PROBLEMS

Slide 7

Slide 7 text

(X : TYPE) -> TYPE -> (X -> TYPE) -> TYPE EFFECT SYSTEMS ▸ Available in Idris and Purescript ▸ Use effects to model state machines.

Slide 8

Slide 8 text

EFFECT PROBLEMS ▸ "it was not possible to implement one effectful API in terms of others" E Brady ▸ "difficult to describe the relationship between separate resources" E Brady ▸ Composing problems?

Slide 9

Slide 9 text

IDRIS IS A PACMAN COMPLETE LANGUAGE Edwin Brady

Slide 10

Slide 10 text

VECTOR LENGTH PROGRAMMING λΠ>:doc Vect Data type Data.Vect.Vect : (len : Nat) -> (elem : Type) -> Type Vectors: Generic lists with explicit length in the type Arguments: len : Nat -- the length of the list elem : Type -- the type of elements Constructors: Nil : Vect 0 elem Empty vector (::) : (x : elem) -> (xs : Vect len elem) -> Vect (S len) elem A non-empty vector of length S len, consisting of a head element and the rest of the list, of length len.

Slide 11

Slide 11 text

PAPER STATES ALL THE WAY DOWN ▸ "A useful pattern in dependently typed programming is to define a state transition system” ▸ “an architecture for dependently typed applications” ▸ “How to implement a state transition system as a dependent type “ ▸ "How to combine state transition systems into a larger system"

Slide 12

Slide 12 text

GENERALISING STATEFUL PROGRAMS ▸ Types should capture the states of resources ▸ Stateful APIs should compose ▸ Types should be readable ▸ Error messages should be readable

Slide 13

Slide 13 text

ENTER STRANS ▸ m - underlying monad ▸ ty - result type of the program ▸ in_ctxt - input context ▸ out_ctxt

Slide 14

Slide 14 text

DATASTORE

Slide 15

Slide 15 text

USING DATASTORE

Slide 16

Slide 16 text

TEXT

Slide 17

Slide 17 text

(.) : (B -> C) -> (A -> B) -> A -> C TYPES OF COMPOSITION ▸ Horizontally - multiple state machines within a function ▸ Vertically - implement state machine in terms of another Examples: Application on a Communication Protocol Multiple resources, File IO plus State

Slide 18

Slide 18 text

STATE PLUS DATASTORE

Slide 19

Slide 19 text

TEXT CLEANING UP THE TYPES ▸ Type level function ST ▸ List of actions on resources

Slide 20

Slide 20 text

DATASTORE - CLEAN

Slide 21

Slide 21 text

TEXT PRETTY ERRORS

Slide 22

Slide 22 text

TEXT CONCLUSION ▸ Need to tie this back to Actors. ▸ Encoding State Machines. ▸ Session Types ▸ Effect Systems

Slide 23

Slide 23 text

TEXT RESOURCES ▸ States All the Way Down, Edwin Brady ▸ Programming and Reasoning with Algebraic Effects and Dependent Types, Edwin Brady ▸ Session Types http://simonjf.com/2016/05/28/session- type-implementations.html ▸ Idris website http://docs.idris-lang.org/