【发布时间】:2012-01-26 09:33:23
【问题描述】:
我正在开发一个函数,它读取“a 2”形式的用户输入,然后将其转换为元组并将其添加到元组列表中。这应该一直发生,直到用户输入“完成”。
代码如下...
getVectorData vector1 = do
putStrLn "Enter dimension and coefficient separated by a space: Enter \"Done\" to move on to next vector: "
appData <- getLine
if appData == "done" then
putStrLn "That's it"
else do
createVectorTuple (words appData) : vector1
getVectorData vector1
createVectorTuple :: [String] -> (String, Float)
createVectorTuple vectorData = ((head vectorData) , (read (last vectorData) :: Float))
然而,当我试图执行这个文件时,我得到了错误
> ERROR file:.\MainApp.hs:13 - Type error in final generator
*** Term : getVectorData vector1
*** Type : IO ()
*** Does not match : [a]
我做错了什么?
【问题讨论】:
-
附带说明,createVectorTuple 函数运行良好。