2

I found that when I execute

a = 1:a
a

in command line, I can press Ctrl+c to stop the infinite process.

But Ctrl+c fails to stop the process when I execute

length a

However, Ctrl+c works well when I execute

length [0..]

Why does Ctrl+c sometimes fail to stop the process? Is there any ways to stop the process when Ctrl+c is invalid?

Gardenia625
  • 123
  • 3
  • Are you running this in GHCi or compiled with GHC and, if so, have you enabled optimizations? – Noughtmare Jun 07 '22 at 08:55
  • In GHCi. What's the difference? – Gardenia625 Jun 07 '22 at 09:00
  • 4
    In this scenario, I'd guess GHC handles C-c only when allocating new memory. If you have a tight loop like the one caused by `length a` which never allocates anything, the thread goes into that loop without any way to escape from it. Probably, it's related to [this bug](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/bugs.html#bugs-in-ghc) and its workaround. – chi Jun 07 '22 at 10:28

1 Answers1

0

Under Windows, there is a bug where, after pressing Ctrl + C, GHCI appears to exit but still seems to run in the background. The only documentation I could find is https://gitlab.haskell.org/ghc/ghc/-/issues/14150 but I've experienced it myself multiple times using version 9.2.1.when working with infinite data structures like infinite lists [1..].

huch
  • 51
  • 4