免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3393 | 回复: 3
打印 上一主题 下一主题

两种风格的代码有何不同啊? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-19 16:19 |只看该作者 |倒序浏览
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)

这是什么原因呢?

论坛徽章:
0
2 [报告]
发表于 2009-10-20 10:53 |只看该作者
因为这里本来是有语法糖的,你用了花括号之后,语法糖不见了,然后就有语法错误了。

写成这样就对了(这也是第二种写法的展开形式):

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);
}

论坛徽章:
0
3 [报告]
发表于 2009-10-20 10:54 |只看该作者
帮flw发的~

论坛徽章:
0
4 [报告]
发表于 2009-10-20 14:52 |只看该作者
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);
}
这样就可以了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP