[Haskell-cafe] two problems with Data.Binary and Data.ByteString
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Thu Aug 14 06:59:53 EDT 2008
Tim Newsham wrote:
[snip]
> I would have expected this to fix my problems:
>
> binEof :: Get ()
> binEof = do
> more <- not <$> isEmpty
> when more $ error "expected EOF"
>
> decodeFully :: Binary b => B.ByteString -> b
> decodeFully = runGet (get << binEof)
> where a << b = a >>= (\x -> b >> return x)
Remember that the Get monad is lazy; the result of binEof is never
used, so the action is not performed.
decodeFully :: Binary b => B.ByteString -> b
decodeFully = runGet (get << binEof)
where a << b = a >>= (\x -> b >>= \y -> y `seq` return x)
works, for example, and also
where a << b = a >>= (\x -> b >>= \y -> return (y `seq` x))
and
where (<<) = liftM2 (flip seq)
HTH,
Bertram
More information about the Haskell-Cafe
mailing list