Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

haskell - "Couldn't match expected type with actual type" error when using Codec.BMP

I have a very little experience in Haskell and I want to write a simple ray tracer for practice. Because I didn't want to use GUI tools like wxHaskell (I think it'll take a lot of time to learn how to use them), I decided to simply save the output image to BMP file. But I have a problem here:

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 first pixel of the image and print its RGBA values. But I get an error saying

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 the pixels of the image and print their values?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have two bytestring packages installed, so unpackBMPToRGBA32 return ByteString from bytestring-0.9.2.1, and BS.putStrLn expects ByteString from other version.

Try ghc-pkg list bytestring to list all bytestring versions installed.

And the solution could be

  • unregister one of them with ghc-pkg unregister bytestring-<version>
  • hide one of them when building: ghc --make -hide-package bytestring-<version>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...