“无法与实际类型匹配的预期类型”使用Codec.BMP时出错 [英] "Couldn't match expected type with actual type" error when using Codec.BMP
问题描述
module Main其中
import Codec.BMP
将符合条件的Data.ByteString导入为BS
main = do
Right bmp< - readBMPgrass.bmp
BS.putStrLn $ BS。取4 $ unpackBMPToRGBA32 bmp
这里我只想取图像的第一个像素并打印它的RGBA值。但是我收到一个错误消息,说:
无法匹配预期的类型`BS.ByteString'
与实际类型`bytestring-0.9.2.1:Data.ByteString.Internal.ByteString'
在`unpackBMPToRGBA32'调用的返回类型中
在`($)'的第二个参数中,即'unpackBMPToRGBA32 bmp'
在`($)'的第二个参数中,即
`BS.take 4 $ unpackBMPToRGBA32 bmp'
我做错了什么?如何获取图像的像素并打印它们的值?
您有两个 bytestring
软件包,所以 unpackBMPToRGBA32
返回 ByteString
from bytestring-0.9。 2.1
和 BS.putStrLn
期望 ByteString
来自其他版本。
尝试 ghc-pkg list bytestring
来列出已安装的所有 bytestring
版本。 / p>
解决方案可以是
- 用<$ c $取消其中一个注册c> ghc-pkg unregister bytestring-< version>
- 构建时隐藏其中的一个:
ghc --make -hide- package bytestring-< version>
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?
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>
这篇关于“无法与实际类型匹配的预期类型”使用Codec.BMP时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!