我有一個函數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