2010-11-11 101 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論文中有解釋。

相關問題