我在 GHC 6.12.3 上编译以下代码时遇到问题,我不明白为什么。
function 的目的test2
是返回一个函数,该函数使用整数从列表中获取字符串元素(列表是从对列表中的第一个节点创建的)。
IO 位是需要的,因为test2
另一个使用 IO 的函数使用。
type PairList = [(String, String)]
test1 :: [String] -> Int -> String
test1 list x = list !! x
test2 :: PairList -> IO (Int -> String)
test2 pl = do
f <- [fst x | x <- pl] :: IO [String]
return test1 f
GHC 给了我这个错误:
Test.hs:8:6:
Couln't match expected type 'IO [String]'
against inferred type '[a]'
In a stmt of a 'do' expression:
f <- [fst x | x <- pl] :: IO [String]
In the expression:
do { f <- [fst x | x <- pl] :: IO [String];
return test1 f }
...