Question

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

Était-ce utile?

La solution

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)

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top