Built monad for state machines, made pipes more type-safe