Haskell: Does ghci show "Chunk .. Empty"?
Asked Answered
C

2

7

Learn You a Haskell has a code example like this:

ghci> B.pack [99,97,110]  
Chunk "can" Empty  

(B stands for Data.ByteString.Lazy)

But my ghci does not show Chunk and Empty data constructors.

> B.pack [99,97,110]  
"can"

Did Haskell developers change the way the values of ByteString are printed?

Corridor answered 25/6, 2013 at 19:26 Comment(3)
What is your version? My 7.4.2 works as LYAH said.Baron
Mine is 7.4.2 too though. I am using Windows. Does it matter?Corridor
Ha, me too, so probably no.Baron
I
12

Looks like Duncan added hand-written Show instance for lazy ByteString somewhere between 0.9.2.1 and 0.10.0.1. See http://hackage.haskell.org/packages/archive/bytestring/0.10.2.0/doc/html/src/Data-ByteString-Lazy-Internal.html#ByteString

Add: Here is the relevant patch

Inferential answered 25/6, 2013 at 19:45 Comment(0)
D
4

Old versions of BL.ByteString simple have a deriving Show in their data declaration. This results in the GHCi output as shown in LYAH, and ensures the output is valid Haskell code. The nice plain string "can" isn't really a valid Haskell representation of that bytestring – that is, not a valid Haskell 98 representation. However, it is common to use {-# LANGUAGE OverloadedStrings #-} in modules that use bytestrings, which makes it valid. Which is probably the reason that there is now (since 0.10) this nicer-to-read manual instance.

Dian answered 25/6, 2013 at 19:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.