Reputation: 3140
Sometimes when using GHCI I accidentally try to evaluate an infinite stream (e.g. [1..]
). It keeps printing... and printing... and printing... and printing... So the problem is that the only way to stop the printing is to quit the console, losing all the stuff that I've already done in that session. Is there a way to make GHCI take only the first x items from a list by default?
Upvotes: 1
Views: 111
Reputation: 101929
Simply use Ctrl+C to interrupt the process:
Prelude > let x = 1
Prelude > [1..]
lots of stuff... Interrupted.
Prelude > print x
1
Other than this I believe you cannot really do anything about it except starting writing your expressions with take
to be sure to have a finite output... In the end lists are only one of possible infinite outputs and the ghci cannot reliably know what requires shortening and what not. He simply show
s the result and output it.
Upvotes: 2