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

Guidelines for using with WriterT #642

Closed
BebeSparkelSparkel opened this issue Jan 15, 2024 · 2 comments
Closed

Guidelines for using with WriterT #642

BebeSparkelSparkel opened this issue Jan 15, 2024 · 2 comments

Comments

@BebeSparkelSparkel
Copy link
Contributor

BebeSparkelSparkel commented Jan 15, 2024

transformers has three versions of WriterT (strict, lazy, CPS) and I am unsure how to best use bytestring with these different writers.

I am guessing that with

  • Builder it would be best to use the strict or CPS version of WriterT.
  • ByteString lazy use strict or CPS version of WriterT
  • ByteString strict and ShortByteString use the lazy version of WriterT

Also, which would allow an exception to be found most quickly?

If you have experience with this, especially with Builder, could you fill me in?

@clyring
Copy link
Member

clyring commented Jan 24, 2024

The differences between the different types of Writer monads are generally not too relevant to bytestring.

As far as the performance characteristics of the various bytestring types goes:

  • Concatenating many StrictByteStrings or ShortByteStrings with (<>) via any sort of writer monad is likely to be very inefficient except in niche situations.
  • Concatenating LazyByteStrings with (<>) can be efficient as long as the calls are generally right-associative. But if the individual LazyByteStrings are short, the result may have a small average chunk size, which may or may not be a problem depending on how that LazyByteString is used.
    • The codensity transform (or adding a ContT layer) can re-associate the monadic binds, if you have many nested calls that would tend to produce inefficient left-associative (<>) calls with a basic writer monad.
  • Concatenating Builders with (<>) is almost always at least reasonably efficient.

@BebeSparkelSparkel
Copy link
Contributor Author

Thanks, I'm working on a biparsing package and I have not yet, if even possible, implemented printing a differing type than the type being parsed. I'll try to figure out how to allow parsing strict or lazy ByteString and printing Builder.

Thank you for the insight.

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