Skip to content

An unlifted ShortText# type #38

@andrewthad

Description

@andrewthad

I've got this defined in one of my projects:

newtype ShortText# :: TYPE ('BoxedRep 'Unlifted) where
  ShortText# :: ByteArray# -> ShortText#
    
lift :: ShortText# -> ShortText
lift (ShortText# x) = TS.fromShortByteStringUnsafe (SBS x)
  
unlift :: ShortText -> ShortText#
unlift t = case TS.toShortByteString t of
  SBS x -> ShortText# x

In GHC 9.4, we can apply Array# to boxed unlifted types (previously, there was a nasty ArrayArray# type that was awful to use), so with this type, we can finally write things like:

Array# ShortText#

I don't technically need for ShortText# to live in text-short, but I thought it might be a reasonable place for it to live. It requires UnliftedNewtypes, which is only available since GHC 8.10.

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