2010-11-11 100 views
2

此错误是什么?错误:无法匹配预期类型Eval [a]'与推断类型()

1.hs:41:30:
Couldn't match expected type 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

我现在没有时间,但尝试通过创建一个文件来定义“strategy”和它需要的任何依赖关系来解决问题。它可能会提供更好的错误消息。 – 2010-11-11 12:44:42

+0

帮助我们标出第41行。 – dave4420 2010-11-11 13:04:43

+0

错误在'losort ++(x:hisort)''使用''策略' – sastanin 2010-11-11 13:25:01

回答

5

大概的问题是,你正在使用rnfControl.Deepseq

rnf :: (NFData a) => a ->() 

这是巧合在parallel < 2.2方面的策略:

type Strategy a = a ->() -- strategy type in early parallel package 

parallelsince 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论文中有解释。

相关问题