A type system for monotonicity Michael Arntzenius University of Birmingham ICFP 2018
It’s just the simply-typed λ -calculus! � A � ∈ Poset � A → B � = monotone maps � A � → � B � , ordered pointwise
op A A ✷ A b b b a c a c a c f : ✷ A → B is monotone iff x = y = ⇒ f ( x ) � f ( y ) i.e. always !
setMap : ✷ ( ✷ A → B ) → Set A → Set B setMap f xs = let box g = f in do x ← xs let box y = x return ( box ( g ( box y )))
setMap : ✷ ( ✷ A → B ) → Set A → Set B setMap f xs = do x ← xs return ( f x )
A < : B id : A → B
[ T ] A < : B id : TA → B T ∈ { id, op, ✷ , ... }
f : TA → B g : UB → C g ◦ f : ( UT ) A → C
Monotonicity tames dragons! 1. Eventual consistency in distributed systems http://bloom-lang.net/calm/ 2. Determinism in parallel programs LVars: Lattice-based Data Structures for Deterministic Parallelism , Lindsey Kuper & Ryan Newton 3. Recursive queries in Datalog & Datafun http://www.rntz.net/datafun 4. Paradoxes of self-reference
fin
subtractEach : List ( Z × op Z ) → List Z subtractEach xs = [ x − y | ( x , y ) ← xs ]
a � b : id A a � b : A ⇐ ⇒ a � b : op A ⇐ ⇒ a � b : A a � b : ✷ A ⇐ ⇒ a � b ∧ a � b : A a � b : ♦ A a � b ∨ b � a : A ⇐ = T UT id op ✷ ♦ ♦ id id op ✷ ♦ op id op op id ✷ ♦ U ✷ ♦ ✷ ✷ ✷ ✷ ♦ ♦ ♦ ✷ ♦
subsumption Γ ⊢ M : A [ T ] A < : B TΓ ⊢ M : C
Recommend
More recommend