【发布时间】:2015-04-26 18:46:49
【问题描述】:
在this tutorial 之后的几个小时内,我确实开始学习 Haskell。尝试编译以下代码时,我不断收到Couldn't match type 错误:
module Main where
import Control.Monad
main = do
putStrLn "Enter child age"
input <- getLine
-- convert the string to int
let age = read input :: Int
unless (age == 0) $ do
-- let ages = []
-- print age
-- add child age to list here?
ages ++ [age]
main
这里是错误:
Couldn't match type `IO' with `[]'
Expected type: [()]
Actual type: IO ()
我已经搜索了几个小时试图理解这个问题,但没有任何线索。为什么 ages ++ [age2] 需要一个类型 IO Int ?以及如何解决这个问题?
更新:ages 是一个包含两个孩子年龄的列表。将来会用到。还创建了循环
【问题讨论】:
标签: string list haskell types integer