Using ghci
, I sometimes enter definitions using multi-line mode (as described in the interactive-evaluation documentation ).
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
.
> :{
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.
Is there any way to edit a previous line in ghci
's multi-line mode without having to type all lines again?
No. GHCi uses Haskeline , which only works on a per-line basis (and does not provide Cx Ce
as GNU Bash does). Essentially, GHCi just works through a queue of lines , which use Haskeline's getInputLine
.
So :{
and :}
only take your code, add "\\n"
inbetween your lines, and then "run it trough the interpreteter". There's no line-buffer you can edit, unfortunately. All you can do is to discard the lines with Cc
and try again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.