Documentation

PolyFun.PFunctor.Handler.Instrumentation.Free

Trace erasure for free handler interpretation #

Discarding writer output is a monad morphism. Naturality of the universal fold therefore transports the one-operation erasure law to every finite free program.

theorem PFunctor.Handler.fst_map_run_liftM_withTraceAppend {p : PFunctor.{uA, u}} {m : Type u → Type v} [Monad m] [LawfulMonad m] {ω α : Type u} [EmptyCollection ω] [Append ω] (handler : Handler m p) (trace : (a : p.A) → p.B a → ω) (program : p.FreeM α) :
Prod.fst <$> (FreeM.liftM (handler.withTraceAppend trace) program).run = FreeM.liftM handler program

Erasing response-dependent trace output recovers the uninstrumented fold.

theorem PFunctor.Handler.fst_map_run_liftM_writerT {p : PFunctor.{uA, u}} {m : Type u → Type v} [Monad m] [LawfulMonad m] {α w : Type u} [Monoid w] (h : Handler (WriterT w m) p) (x : p.FreeM α) :
Prod.fst <$> (FreeM.liftM h x).run = FreeM.liftM (fun (a : p.A) => Prod.fst <$> (h a).run) x

Forgetting the log of any handler into a writer recovers the run of the handler with its logs forgotten.