Reputation: 1131
I am trying to do some image manipulation in Haskell with an image library. Opening the image with the library requires a ByteString
type. I want to test the library in ghci but when I load a file it has the type IO ByteString
and cannot be used.
How can I unpack the ByteString
data from the IO ByteString
type in ghci?
Upvotes: 1
Views: 192
Reputation: 152867
fmap
teaches pure functions how to muck about with impure inputs:
fmap :: (a -> b) -> IO a -> IO b
and (=<<)
teaches impure functions how to muck about with impure inputs:
(=<<) :: (a -> IO b) -> IO a -> IO b
And, of course, in ghci, there is the handy do
-notation available as a shorthand for uses of (=<<)
, so that if you write
> x <- Data.ByteString.readFile "/path/to/image.jpg"
then you will have x :: ByteString
bound in the remainder of your session, even though Data.ByteString.readFile "/path/to/image.jpg" :: IO ByteString
.
Upvotes: 5