这是问题所在。它看起来很简单
main = do
s <- getContents
let list = map (read::Int) (words s)
print list
Couldn't match expected type `Int' with actual type `String -> a0'
Probable cause: `read' is applied to too few arguments
In the first argument of `map', namely `(read :: Int)'
In the expression: map (read :: Int) (words s)
问题是我认为::就像投射一样,我必须把返回类型。解决方案是添加完整的通缉|函数签名instread。
答案 0 :(得分:3)
read
是一个函数(Read a => String -> a
类型),因此它不能具有类型Int
。你可以read :: String -> Int
,或者你可以在list
而不是read
上设置类型签名,这样你就得到了:
let list :: [Int]
list = map read (words s)