~/talk

Monad Transformer State

Talkat Lambda World 2017 · 2017-10-26..10-27· [haskell, functional-programming]
slides:none on file

Claim: lifting control-style IO functions over transformers that carry mutable monadic state can silently discard updates. Demonstrations use lifted-async and monad-control: concurrently run on StateT consistently yields the second thread’s state (concurrently returns second thread's state, always 4), and bracket semantics differ by library (bracket semantics differ between libraries). Workarounds: restrict app monad to ReaderT/RIO and use real mutable cells (IORef/STM) instead of StateT for shared/updatable state, or use unliftio for safe unlifting where it’s supported.

AI-written summary · about

  1. 0:00Intro
  2. 0:50What's a monad transformer?
  3. 1:29Which transformers are we covering?
  4. 2:27Meet the transformers
  5. 3:09A concurrent problem
  6. 6:52Ask, lift, and run • Don't need to use explicit data constructor unwrapping
  7. 8:35Pop quiz! What is the output of this program
  8. 14:01Take a step back 1. This is not just a bug in implementation 2. The ambiguity and discarding is inherent to implementing the algorithm 3. We cannot implement some classes of functions for
  9. 15:25But does it lift? Which of these functions can be converted to stater
  10. 16:47Monad transformer environment versus state
  11. 21:14Natural linear call path Even though catch has two input actions, the handler is only called after the main action completes
  12. 23:23The problem cases Two categories of problem cases 1. Things like finally: can manually reimplement
  13. 23:52Cheating
  14. 29:16Use mutable variables
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.