无法在GHCi中输入多行语句 [英] Cannot enter multiline statements in GHCi

查看:89
本文介绍了无法在GHCi中输入多行语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

let x=1
    y=2
    z=3

在GHCi中不起作用,迫使我改用let {x=1;y=2;y=3}.我该如何解决这个问题?

does not work in GHCi, forcing me to use let {x=1;y=2;y=3} instead. How can I fix this problem?

推荐答案

文档说:

GHCi还具有由:set + m启用的多行模式,在该模式下,GHCi在当前语句未完成时自动检测并允许添加更多行.多行输入以空行终止.

GHCi also has a multiline mode, enabled by :set +m, in which GHCi detects automatically when the current statement is unfinished and allows further lines to be added. A multi-line input is terminated with an empty line.

多行模式使GHCi的行为类似于Python解释器:

The multiline mode makes GHCi behave much like e.g. the Python interpreter:

Prelude> :set +m
Prelude> let x = 1
Prelude|     y = 2
Prelude|     z = 3
Prelude|
Prelude> (x, y, z)
(1,2,3)

这个隐藏的宝石非常适合与可读代码一起玩!

This hidden gem is wonderful for playing with readable code!

如果您希望将其作为默认行为,则可以在主目录中创建一个.ghci文件,并在一行中显示:set +m. (现在出现了,我实际上是这样做的.)

If you want this to be the default behaviour, you can create a .ghci file in your home directory with a line saying :set +m. (Now that this came up, I actually did so.)

这篇关于无法在GHCi中输入多行语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆