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

Swap genShortByteString for genByteArray #142

Closed
Bodigrim opened this issue Sep 10, 2023 · 2 comments · Fixed by #153
Closed

Swap genShortByteString for genByteArray #142

Bodigrim opened this issue Sep 10, 2023 · 2 comments · Fixed by #153

Comments

@Bodigrim
Copy link
Contributor

Since bytestring-0.12 ShortByteString is just a newtype over ByteArray, a common data type shared by base, text and primitive.

I think we can make class Random more useful if we swap

-genShortByteString :: Int -> g -> (ShortByteString, g)
+genByteArray Int -> g -> (ByteArray, g) 

This way we can shave off dependency on bytestring and do not impose it on our users.

There does not seem to be many users of genShortByteString in the wild. Potentially we can provide a compatibility shim:

genShortByteString :: Coercible a ByteArray => Int -> g -> (a, g)
genShortByteString = coerce genByteArray
@lehins
Copy link
Contributor

lehins commented Sep 10, 2023

I had the same idea the moment you released the byte-array package.

This way we can shave off dependency on bytestring and do not impose it on our users.

I don't think this is terribly important, in fat I'd be against it, especially considering that bytestring is one of the wired-in packages. I'd be against it because ability to generate ByteString and ShortByteString efficiently out of the box is a great feature. I've personally used it on multiple occasions, including at work (which is not gonna show up at hackage search).

That being said, I do agree with you 100% requiring in RandomGen:

genByteArray :: Int -> g -> (ByteArray, g)

instead of

genShortByteString :: Int -> g -> (ShortByteString, g)

and

uniformByteArray :: Int -> g -> m ByteArray

instead of

uniformShortByteString :: Int -> g -> m ShortByteString

in StatefulGen

Makes a lot of sense.

ShortByteSring variants can just be extracted into standalone functions.

@Shimuuar
Copy link
Contributor

+1 for switching to ByteArray. As for dropping dependency on bytestring I see no reason to do so. It's basically a part of a standard library

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

Successfully merging a pull request may close this issue.

3 participants