Error "Could not match expected type with actual type" when using Codec.BMP

I have very little experience with Haskell, and I want to write a simple ray tracer for practice. Since I did not want to use GUI tools such as wxHaskell (I think it would take a long time to learn how to use them), I decided to just save the output image to a BMP file. But I have a problem:

module Main where

import Codec.BMP
import qualified Data.ByteString as BS

main = do
  Right bmp <- readBMP "grass.bmp"
  BS.putStrLn $ BS.take 4 $ unpackBMPToRGBA32 bmp

Here I just want to take the first pixel of the image and print its RGBA values. But I get an error

Couldn't match expected type `BS.ByteString'
            with actual type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString'
In the return type of a call of `unpackBMPToRGBA32'
In the second argument of `($)', namely `unpackBMPToRGBA32 bmp'
In the second argument of `($)', namely
  `BS.take 4 $ unpackBMPToRGBA32 bmp'

What am I doing wrong? How can I take image pixels and print their values?

+5
source share
1 answer

bytestring, unpackBMPToRGBA32 bytestring bytestring-0.9.2.1, BS.putStrLn bytestring .

ghc-pkg list bytestring bytestring.

  • ghc-pkg unregister bytestring-<version>
  • : ghc --make -hide-package bytestring-<version>
+9

All Articles