haskellimportrepa

Not in scope error when trying to use Repa package


I'm relatively new to Haskell, and I'm trying to use Repa package in a project. I have imported the package in my source code using import qualified Data.Array.Repa as R, but when loading the Haskell file in ghci, I get the following error:

Location_repa.hs:46:26:
Not in scope: type constructor or class `D'
Perhaps you meant `R.D' (imported from Data.Array.Repa)

Location_repa.hs:46:29:
Not in scope: type constructor or class `Z'
Perhaps you meant `R.Z' (imported from Data.Array.Repa)

Location_repa.hs:46:30:
Illegal operator `:.' in type `Z :. (Dimension :: Int)'
Use TypeOperators to allow operators in types
.....

And here is the part of source code that uses Repa:

type CoordList = Array D (Z:. (Dimension::Int)) Integer

It seems as if the package is not imported (loaded). Using ghc-pkg list repa results in the following:

C:/Program Files/Haskell Platform/7.10.2-a\lib\package.conf.d:
(no packages)
C:\Users\...\AppData\Roaming\ghc\x86_64-mingw32-7.10.2\package.conf.d:
repa-3.4.1.1

What should I do?


Solution

  • It looks like you have two problems. First, you're importing the module qualified, but using it unqualified. You can add an additional import for definitions that you don't want to have to qualify:

    import Data.Array.Repa (D,Z,(:.))
    

    The second problem is what the third error message is telling you. You need to turn on the TypeOperators extension. Put this at the top of your file:

    {-# LANGUAGE TypeOperators #-}