Control.Parallel compile issue in Haskell

2020-08-09 11:28发布

问题:

The compiler is complaining each time on different example applications of parallel Haskell; with this message:

Could not find module `Control.Parallel.Strategies'

The ghc compiler command:

ghc -threaded -i/sudo/dir/par-modules/3 -cpp -DEVAL_STRATEGIES -eventlog --make parFib.hs

Same with simpler

ghc -O2 --make -threaded parFib.hs

What detail am I overlooking? Am I missing some PATH variable.

Imports can look like this:

module Main where
import System
#  if defined(EVAL_STRATEGIES)
import Control.Parallel
import Control.Parallel.Strategies
#endif

Cheers

回答1:

You must install the parallel package from Hackage. In most sane setups, this should be as simple as typing

cabal install parallel # note: not sudo cabal install parallel!

at your command prompt.



回答2:

I'm adding a new answer (instead of a comment) for visibility reasons.

After trying Daniel's answer, I still wasn't able to do import Control.Parallel, neither from ghci, nor with the compiler. The install command returned a warning message like this:

➜  ~ cabal install parallel
Resolving dependencies...
Up to date
Warning: You asked to install executables, but there are no executables in
target: parallel. Perhaps you want to use --lib to install libraries instead.

What ultimately resolved the issue was:

cabal install --lib parallel


回答3:

Like Daniel said, you'll need the parallel package. However if you'd prefer to use your system's package manager (which some people think you should), you can.

Note that, at least in the Fedora repos, you'll need ghc-parallel-devel, not just ghc-parallel to build.

#yum install ghc-parallel-devel