Home > OS >  What does `BytesPrimL` represent?
What does `BytesPrimL` represent?

Time:08-12

I can figure out what most literals represent with ppr, e.g. WordPrimL 7 = 7##, CharPrimL 'x' = 'x'#, etc. The only constructor I can't figure out is BytesPrimL:

λ> bytes <- mallocForeignPtrArray @Word8 5
λ> let bytesLit = LitE (BytesPrimL (mkBytes bytes 0 5)
λ> ppr bytesLit
"<binary data>"

So, what code would generate an Exp with a BytesPrimL constructor? What is it supposed to represent?

CodePudding user response:

ghci> bytes <- mallocForeignPtrArray @Word8 5
ghci> let bytesLit = LitE (BytesPrimL (mkBytes bytes 0 5))
ghci> :t $(pure bytesLit)
$(pure bytesLit) :: GHC.Prim.Addr#

I'm pretty sure there is no Haskell code that corresponds to that. Instead, this is piggy-backing on the way GHC already compiles string literals to allow you to embed arbitrary binary data in the executable efficiently.

  • Related