1

I am trying to use the length function of the streaming-bytestring Data.ByteString.Streaming.Char8 library.

I see that the return value has type Of, but I am not clear on how to examine it. I tried using case, but the compiler says Not in scope: data constructor ‘O.Of’, even if I do a qualified import of Data.Functor.Of.

How do I examine the value?

Code sample:

ghci> let bs = BSSC.string "tiger"            
ghci> bs                                                   
Chunk "tiger" (Empty (()))                                            
ghci> BSSC.length bs                 
6 :> ()                                  
ghci> let len = BSSC.length bs
ghci> :t len
len :: Monad m => m (OO.Of Int ())
danidiaz
  • 26,936
  • 4
  • 45
  • 95
paperduck
  • 1,175
  • 1
  • 16
  • 26
  • 2
    Can you provide a minimal working example (a small code fragment with the given error, such that we can see what is going on)? – Willem Van Onsem May 14 '19 at 07:11
  • 1
    You can find out how to construct `Of` by writing `:info Of` in GHCi, or using [Hoogle](https://hoogle.haskell.org/?hoogle=Of). – AJF May 14 '19 at 08:52

1 Answers1

6

The constructor of Of is called (:>):

-- | A left-strict pair; the base functor for streams of individual elements.
data Of a b = !a :> b
    deriving (Data, Eq, Foldable, Ord,
              Read, Show, Traversable, Typeable, Generic, Generic1)
infixr 5 :>

so you should be able to do something like

n :> _ <- length bs
Cactus
  • 27,075
  • 9
  • 69
  • 149