[Haskell] lazy printing
Serge D. Mechveliani
mechvel at botik.ru
Fri Sep 10 06:16:47 EDT 2004
Dear Haskellers,
Can you tell me how to force Haskell to output the results in a
`lazy' way?
Consider, for example, the program
main = putStr (concat ["\n min1 = ", show min1,
"\n min2 = ", show min2,
"\n"
]
)
where
min1 = minimum [1 .. 10 ] :: Integer
min2 = minimum [1 .. (10^10)] :: Integer
I do not know whether the effect is due to implementation.
And I `make'-run the program under GHC-6.2.2-pre by commanding
ghc -O --make Main
./a.out
This prints min1 = 1
and hangs silently -- probably, because min2 takes long to compute.
But why does not it print immediately
min1 = 1
min2 =
?
This is for the first time in my practice that a `lazy' printing is
essential.
The above example is contrived.
The real example is a program that searches for the proof and
accumulates a certain
ptrace :: ProofTrace,
type ProofTrace = [Step]
The first steps are performed easily, and also they are informative.
So, the user should see their results immediately -- when one applies
(show ptrace).
The whole proof may take long, the last steps in ptrace may be
ready after a very long time.
And Haskell just holds until the whole ptrace is ready, which is
annoying.
Copy, please, the answer to mechvel at botik.ru
With kind regards,
-----------------
Serge Mechveliani
mechvel at botik.ru
More information about the Haskell
mailing list