I have a function in Haskell:

import qualified Codec.Picture as Juicy

--juicyLoad :: FilePath -> IO (Vector Word8)
juicyLoad file = do
    image <- Juicy.readPng file

    case image of
        Left err -> undefined
        Right (Juicy.ImageRGB8 (Juicy.Image w h dat)) ->
            return dat

GHC infers the type to be FilePath -> IO (Vector Word8), which is what I want. When I actually define that in the source file (juicyLoad :: FilePath -> IO (Vector Word8)), there is an error: Couldn't match expected type 'Vector Word8' with actual type 'Vector(PixelBaseComponent PixelRGB8'.

This seems like a job for a {-# LANGUAGE x #-} option, I just don't know which one

有帮助吗?

解决方案

There are several different versions of Vector. I was able to fix this by explicitly importing the same one that is inferred by GHC.

import qualified Codec.Picture as Juicy
import Data.Vector.Storable
import GHC.Word

And declaring the type like this:

juicyLoad :: FilePath -> IO (Vector Word8)

其他提示

The problem was my importing of the Vector type. I was importing Data.Vector, the correct import is Data.Vector.Storable.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top