简体   繁体   English

如何在ghci的多行模式中编辑前一行?

[英]How to edit prior line in ghci's multi-line mode?

Using ghci , I sometimes enter definitions using multi-line mode (as described in the interactive-evaluation documentation ). 使用ghci ,我有时会使用多行模式输入定义(如交互式评估文档中所述 )。

For instance, 例如,

> :{
Prelude| sumToN :: (Eq a, Num a) => a -> a
Prelude| sumToN n
Prelude|   | signum n /= 1 = 0
Prelude|   | otherwise = 1 + sumToN (n-1)
Prelude| :}
>

When using this multi-line input mode, I occasionally realize that I have made a mistake in my input on a previous line. 当使用这种多线输入模式时,我偶尔会发现我在前一行的输入中出错了。 For example, in this code I accidentally typed A instead of a . 例如,在这段代码中我偶然输入了A而不是a

> :{
Prelude| sumToN :: (Eq a, Num a) => a -> A
Prelude|

To correct the mistake I need to edit a prior line. 要纠正错误,我需要编辑前一行。 However, I cannot find any way to go back and edit a previous line. 但是,我找不到任何方法可以返回并编辑上一行。 Instead, I ^C out of the multi-line mode and start again, repeating if necessary until I type the whole definition line-by-line without mistakes. 相反,I ^C退出多线模式并重新开始,必要时重复,直到我逐行输入整个定义而没有错误。

Is there any way to edit a previous line in ghci 's multi-line mode without having to type all lines again? 有没有办法在ghci的多行模式中编辑前一行而不必再次键入所有行?

No. GHCi uses Haskeline , which only works on a per-line basis (and does not provide Cx Ce as GNU Bash does). GHCi使用Haskeline ,它只能在每行的基础上工作(并且不像GNU Bash那样提供Cx Ce )。 Essentially, GHCi just works through a queue of lines , which use Haskeline's getInputLine . 从本质上讲,GHCi只是通过一个使用Haskeline的getInputLine 的行队列来工作。

So :{ and :} only take your code, add "\\n" inbetween your lines, and then "run it trough the interpreteter". 所以:{:}只接受你的代码,在你的行之间添加"\\n" ,然后“通过解释器运行它”。 There's no line-buffer you can edit, unfortunately. 遗憾的是,您无法编辑行缓冲区。 All you can do is to discard the lines with Cc and try again. 你所能做的就是用Cc丢弃这些线,然后再试一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM