Haskell - “”do“结构中的最后一个语句必须是表达式” [英] Haskell -- "The last statement in a 'do' construct must be an expression"
本文介绍了Haskell - “”do“结构中的最后一个语句必须是表达式”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如标题中所说:
的意思?我用 putStrLn
来结束我的 do
块,就像我在前面看到的几个示例中显示的那样,并且出现错误。
代码:
main = do args< - getArgs
file< -readFile" TWL06.txt
putStrLn结果
大多数情况下,这是因为你的代码是错误对齐的,编译器会认为你的do块过早地结束了(或者有额外的代码不属于那里)。 $ b
Like it says in the title: What does The last statement in a 'do' construct must be an expression
mean? I ended my do
block with a putStrLn
like it shows in several examples I've seen, and i get an error.
Code:
main = do args <- getArgs
file <-readFile "TWL06.txt"
putStrLn results
解决方案
Most of the time, it's because your code is mis-aligned and compiler assumes that your "do" block ended prematurely (or has extra code that dont really belong there)
这篇关于Haskell - “”do“结构中的最后一个语句必须是表达式”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文