Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPS version of ChronicleT #173

Open
pkamenarsky opened this issue Apr 4, 2022 · 3 comments
Open

CPS version of ChronicleT #173

pkamenarsky opened this issue Apr 4, 2022 · 3 comments

Comments

@pkamenarsky
Copy link

Would it make sense to add a CPS version of ChronicleT, similar to Control.Monad.Trans.Writer.CPS, in order to achieve constant space usage?

@phadej
Copy link
Collaborator

phadej commented Apr 8, 2022

What that version would look like? Note that Chronicle is closer to Either / ExceptT, and CPS variants of these are not in transformers / mtl. They could, there are some versions in e.g. unification-fd

newtype EitherKT e m a = EKT (forall r. (a -> m (Either e r)) -> m (Either e r))

and there could be one more often used in parsers

newtype EitherCpsT e m a = ECT (forall r. (a -> m r) -> (e -> m r) -> m r)

but i'd prefer seeing this in transformers / mtl first to then follow their overall style, module naming, type naming scheme, etc.

@pkamenarsky
Copy link
Author

I was thinking about something like:

newtype ChronicleT c m a = ChronicleT { runChronicleT :: c -> m (These c a) }

So that dictate (the equivalent of tell) doesn't accumulate mappend thunks:

dictate :: (Semigroup c, Monad m) => c -> ChronicleT c m ()
dictate c' = ChronicleT $ \c -> let ct = c `mappend` c' in ct `seq` pure (These ct ())

@phadej
Copy link
Collaborator

phadej commented Apr 8, 2022

I see. Ok, I'll be happy to review a PR adding that in .CPS module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants