Question

I'm trying to examine the RGB components of pixels in an image, but I can't figure out how to do it.

import Data.Array.Repa
import Data.Array.Repa.IO.DevIL
import Data.Word (Word8)

main = do
  (RGB ps) <- runIL $ readImage "test.jpeg"
  let k = (Z :. 142) :. 212 :. 0 :: DIM3
  print $ ps ! k

The error I get is:

[1 of 1] Compiling Main             ( amy.hs, interpreted )

amy.hs:8:15:
    Couldn't match expected type `Array r0 DIM3 a0'
                with actual type `repa-3.2.3.1:Data.Array.Repa.Base.Array
                                    repa-3.2.3.1:Data.Array.Repa.Repr.ForeignPtr.F
                                    repa-3.2.3.1:Data.Array.Repa.Index.DIM3
                                    Word8'
    In the first argument of `(!)', namely `ps'
    In the second argument of `($)', namely `ps ! k'
    In a stmt of a 'do' block: print $ ps ! k
Failed, modules loaded: none.

For starters, I don't understand the message. It looked like the compiler expected an Array something DIM3 something, and it got an Array F DIM3 Word8. Why don't these types match up? I've read the Repa Tutorial on the Haskell wiki, but I still don't see how to make this work.

Was it helpful?

Solution

I think you may have two different versions of repa in play. Check by saying

ghc-pkg list repa

and see how many versions show up. I suspect you're importing Data.Array.Repa from one instance, but Data.Array.Repa.IO.DevIL depends on the other. The hint is in the error message:

Couldn't match expected type `Array r0 DIM3 a0'
            with actual type `repa-3.2.3.1:Data.Array.Repa.Base.Array

Once, GHC says Array, and once, it says repa-3.2.3.1:Data.Array.Repa.Base.Array. This usually means that it explicitly wants to make a difference between two occurrences of the type Array here.

If my suspicion is correct, you can either hide one version of repa (the one that's not version 3.2.3.1 and being used by repa-devil) by passing

-hide-package repa-<version>

(with the correct version number filled in) to GHC, or you can hide the package via

ghc-pkg hide repa-<version>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top