Skip to content

error function is not lazy

C:\Neil\Temp>type Test.hs
main = error $ cycle "Hello\n"
C:\Neil\Temp>ghc --make Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test.exe ...
C:\Neil\Temp>test
-- hangs forever

The error message seems to get buffered, which means long/infinite messages are never displayed. GHCi does evaluate error lazily. The error function is particularly useful for debugging, which is where I encountered this problem.

It appears trace has a similar issue of buffering in GHC compiled programs, but I am not certain.

Trac metadata
Trac field Value
Version 6.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information