我有一个函数getImage,它接受DynamicImage类型的输入并将其更改为图像。功能如下尝试在构造函数值上执行haskell模式匹配
getImage (ImageY8 image) = image
getImage (ImageY16 image) = image
以上定义来自Codec.Picture模块。但它给了我一个错误:
Couldn't match type ‘GHC.Word.Word16’ with ‘GHC.Word.Word8’
Expected type: Image Pixel8
Actual type: Image Pixel16
In the expression: image
In an equation for ‘getImage’: getImage (ImageY16 image) = image
Failed, modules loaded: none.
这是为什么不工作,我可以做到以下几点:
data Shape = Circle Float | Rectangle Float Float
area (Circle r) = 3.14 * r * r
area (Rectangle a b) = a * b
这是类似我的问题。
JuicyPixels更好。我在哪里可以找到它的proprer文档? –
对不起,我的英文被打破了。我想在括号中说,我猜你已经使用了“JuicyPixels”,但你没有在你的问题中指出它。有'Codec.Picture',但它的名字可以被任何其他软件包使用。 这是你想问的吗? – QuietJoon