我有一个字符串列表,并尝试了这个:
ls = [ "banana", "mango", "orange" ]
main = do
map PutStrLn list_of_strings
那没有用,我不明白为什么。
ghc print-list.hs
print-list.hs:3:0:
Couldn't match expected type `IO t' against inferred type `[IO ()]'
In the expression: main
When checking the type of the function `main'
有什么提示吗?我想这与 map 返回一个列表而不是一个值有关,但我没有找到一种简单的方法来解决这个问题。
现在我知道打印字符串列表的唯一方法是编写一个函数来迭代列表,打印每个元素(如果列表是 [a] 则打印,但如果它是 (a:b) 则打印并递归)。但是只使用地图会简单得多......
谢谢!