这个错误是什么?
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
Run Code Online (Sandbox Code Playgroud)
也许问题是,你正在使用rnf从Control.Deepseq
rnf :: (NFData a) => a -> ()
Run Code Online (Sandbox Code Playgroud)
巧合的是这个策略parallel < 2.2:
type Strategy a = a -> () -- strategy type in early parallel package
Run Code Online (Sandbox Code Playgroud)
但是从版本2.2开始parallel,策略有不同的类型:
type Strategy a = a -> Eval a
Run Code Online (Sandbox Code Playgroud)
PS最新版本parallel是3.1.0.1.您可以考虑阅读API修订的完整历史记录.据我所知,最新的API版本在Seq no More:Better Strategies for Parallel Haskell论文中有所解释.
| 归档时间: |
|
| 查看次数: |
199 次 |
| 最近记录: |