Cannot enter multiline statements in GHCi [duplicate]

纵然是瞬间 提交于 2020-02-27 23:13:46

问题


let x=1
    y=2
    z=3

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


回答1:


The documentation says:

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.

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!

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.)



来源:https://stackoverflow.com/questions/18162420/cannot-enter-multiline-statements-in-ghci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!