purescript/purescript-transformers

MonadRec instance for RWST

ethul opened this issue · 3 comments

There looks to be instances for the other transformers, but not RWST.

I wanted to submit this for tracking, unless it is intentionally not provided.

This should exist, but the version which was implemented in a previous PR was very slow. I think changing RWS to use an ADT instead of a record (See) would help.

I have an instance defined in a branch, but I will wait on sending a PR.

instance monadRecRWST :: (Monoid w, MonadRec m) => MonadRec (RWST r w s m) where
  tailRecM k a = RWST \r s -> tailRecM (k' r) { writer: mempty, state: s, result: a }
    where
    k' r o = do
      see <- runRWST (k o.result) r o.state
      return case see.result of
                  Left a -> Left { state: see.state, result: a, writer: o.writer <> see.log }
                  Right b -> Right (mkSee see.state b (o.writer <> see.log))

Is this similar to previous definition?

I am wondering if any performance tests/results for the old implementation happen to still be around. I'd be curious to take a look at them.

garyb commented

Looks like this was added at some point!