Shared State In Pure Fp When A State Monad Won't Do
summary
State monad is sequential and fails for concurrent servers; use effectful primitives instead. Shows a concrete Ref[F,A] implemented with java.util.concurrent.AtomicReference inside IO, exposing get/set/update/modify and a CAS retry loop that is lock‑free and guarantees progress. Recipe: suspend creation/access/modification in IO (return F[Ref[F,A]]), or wrap mutable resources with Sync/Resource. Result: sharing becomes syntactic — regions of sharing = call graph — enabling compositional, testable concurrent state.
AI-written summary · about
chapters (14)
- 0:00Introduction to talk
- 1:06What is pure functional programming
- 4:55Why referential transparency matters
- 7:01Understanding State and its limits
- 8:30State monad explained
- 13:23State monad in practice
- 16:31Why State monad won’t suffice
- 19:22Using IO for shared state
- 20:30Implementing a Ref primitive
- 27:11Using Ref in programs
- 30:40Sharing and isolating state
- 32:25Key property of shared state
- 33:26Final tagless algebras
- 36:58Summary and conclusion
related talks
30mCONQUERING CONCURRENCY WITH FUNCTIONAL PROGRAMMING
36mComposable concurrency with Ref + Deferred
38mIntro to FP in Scala: Exploring a Toolbox for Solving Problems - Part 5 of 6
34mMonad Transformer State
34mThe Art of Functional State Management
50mFunctional Programming with Effects
20mIndex your State for Safer Functional APIs
28mThe Art of Functional State Management
