两种风格的代码有何不同啊?
winSSQ count noRed noBlue = do {
let yesRed = [1..33] \ noRed;
let yesBlue = [1..16] \ noBlue;
bracket (openFile "ssqNum.txt" WriteMode) (hClose) (hd1 -> pickSSQ count yesRed yesBlue hd1);
}
将报错: parse error on input `let' !
但下面代码却正确!
winSSQ count noRed noBlue = do
let yesRed = [1..33] \ noRed
let yesBlue = [1..16] \ noBlue
bracket (openFile "ssqNum.txt" WriteMode) (hClose) (hd1 -> pickSSQ count yesRed yesBlue hd1)
这是什么原因呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
winSSQ count noRed noBlue = do {
let {yesRed=[1..33] \ noRed; yesBlue=[1..16] \ noBlue};
bracket (openFile "ssqNum.txt" WriteMode) (hClose) (hd1 -> pickSSQ count yesRed yesBlue hd1);
}
这样就可以了!
帮flw发的~
因为这里本来是有语法糖的,你用了花括号之后,语法糖不见了,然后就有语法错误了。
写成这样就对了(这也是第二种写法的展开形式):
winSSQ count noRed noBlue = do {
let yesRed = [1..33] \ noRed;
in let yesBlue = [1..16] \ noBlue;
in bracket (openFile "ssqNum.txt" WriteMode) (hClose) (hd1 -> pickSSQ count yesRed yesBlue hd1);
}