问题
I'm just beginning with Haskell and playing around with GHCi in cmd. After trying out something I saw on PPCG, I ran into an issue. Whenever I interrupt fix
with control-C, everything dies:
C:\Users\Scrooble>ghci
GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help
Prelude> import Data.Function
Prelude Data.Function> fix (\x -> x + 1)
In^tCerrupte
d.
C:\Users\Scrooble>Prelude Data.Function> exit
(hangs)
The ^
and C
were my keyboard interrupt. The exit
is mine as well.
Cerrupted
is right! What is going on?! I seem to have halfway exited GHCi. When I interrupt the exit
(prompt is Prelude Data.Function>
again) and :q
it, cmd sometimes just closes and sometimes prompts me with C:\Users\Scrooble
once more; however, when this happens, the first character of all my commands is ignored!
C:\Users\Scrooble>exit
'xit' is not recognized as an internal or external command,
operable program, or batch file.
0.o
Am I alone in this? Is there a fix
(ha) (other than not doing stupid things)?
HP ProBook 4535s, with Windows 7 Professional, 64-bit. AMD A4-3300M APU processor.
The same happens in PowerShell as well. In Git Bash, the window freezes after I interrupt the fix
.
Edit:
I've now experienced this when interrupting other infinite recursion, like my mergesort that (whoops!) didn't treat singletons as necessarily sorted.
回答1:
I think this might be fixed in ghc-8.2.2.
回答2:
It looks like you're running Haskell platform installed on Windows. I used to to that, but these days I run everything through Stack, so I may remember the following incorrectly.
IIRC, though, when you attempt to run ghci
in Windows, it explicitly prints a warning that ghci
is known to have problems with break commands on Windows, and that you should instead run GHCi via the batch command ghcii.bat
.
Back when I used the Haskell platform, I always ran with ghcii.bat
, and typically didn't have those problems. I've always used Haskell from within Git Bash, which is my default CLI on Windows, so that could be a determining factor as well.
These days I use Stack on Windows 10, and from within Git Bash, I can't reproduce the problem:
$ stack ghci
Prelude> :m +Data.Function
Prelude Data.Function> fix (\x -> x + 1)
Interrupted.
Prelude Data.Function>
The Interrupted.
line is where I hit Ctrl+C. When I did that, the blocking application of fix
immediately exited, and the REPL was ready for action.
来源:https://stackoverflow.com/questions/50054085/haskell-statements-in-ghci-being-interrupted-seems-to-break-cmd