这是什么错误?
1.hs:41:30:
无法匹配预期类型Eval [a]' against inferred type
()
module Main where
import Control.Parallel(par,pseq)
import Text.Printf
import Control.Exception
import System.CPUTime
import Data.List
import IO
import Data.Char
import Control.DeepSeq
import Control.Parallel.Strategies
--Calcula o tempo entre o inicio e o fim de rodagem do programa
time :: IO t -> IO t
time a = do
start <- getCPUTime
v <- a
end <- getCPUTime
let diff = (fromIntegral (end - start)) / (10^12)
printf "Computation time: %0.3f sec\n" (diff :: Double)
return v
learquivo :: FilePath -> IO ([[Int]])
learquivo s = do
conteudo <- readFile s
return (read conteudo)
main :: IO ()
main = do
t1 <- getCPUTime
conteudo <- learquivo "list.txt"
let !mapasort = (map qsort conteudo) `using` (parList rdeepseq)
t2 <- getCPUTime
let difft2t1 = (fromIntegral (t2 -t1)) / (10^12)
printf "Computation time %0.3f sec" (difft2t1 :: Double)
qsort [] = []
qsort [x] = [x]
qsort (x:xs) =
` losort ++ (x:hisort) `using` strategy `
where
losort = qsort [y|y <- xs, y < x]
hisort = qsort [y|y <- xs, y >= x]
strategy result = rnf losort `par`
rnf hisort `pseq`
rnf result
答案 0 :(得分:5)
问题可能是您使用rnf
Control.Deepseq
rnf :: (NFData a) => a -> ()
这恰好是parallel < 2.2
:
type Strategy a = a -> () -- strategy type in early parallel package
但是parallel
since version 2.2,策略的类型不同:
type Strategy a = a -> Eval a
P.S。 parallel
的最新版本是3.1.0.1。您可以考虑阅读the complete history of API revisions。据我了解,最新的API版本在Seq no More: Better Strategies for Parallel Haskell论文中有解释。