Skip to content

Swap genShortByteString for genByteArray #142

Description

@Bodigrim

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

Activity

  1. lehins commented on Sep 10, 2023

    @lehins
    Contributor

    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.

  2. Shimuuar commented on Sep 10, 2023

    @Shimuuar
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions