【发布时间】:2016-03-16 13:37:54
【问题描述】:
首先我是新来的,感谢您的帮助。
问题基本上是我无法在 Haskell 中使用 writeFile 写入文件。 代码:
main = do
putStrLn "Input file: "
ifile <- getLine
result <- readFile ifile >>= print . emit . compile . calc . lexer
print result
这是我目前拥有的,我知道函数 emit 正在正确返回。
我正在使用的功能的其他信息:
emit :: (Int, Int, [Stuff]) -> String
compile :: C -> (Int, Int, [Stuff])
我可以用上面的代码打印结果,它返回如下:
"stuff i want"
()
我觉得() 很有趣,但我想我可以在之后将其从文件中删除。
当我尝试以下列方式使用 writeFile 时:
writeFile "file.txt" results
它给了我以下错误:
Couldn't match type `()' with `[Char]'
Expected type: String
Actual type: ()
In the second argument of `writeFile', namely `result'
In a stmt of a 'do' block: writeFile "result.txt" result
In the expression:
do { putStrLn "Input file: ";
ifile <- getLine;
result <- readFile ifile >>= print . emit . compile . calc . lexer;
writeFile "result.txt" result }
有人知道我该如何解决这个问题吗? 提前致谢!
【问题讨论】: