[Haskell-cafe] Strict evaluation not working?
Jon Fairbairn
Jon.Fairbairn at cl.cam.ac.uk
Tue Oct 12 12:20:09 EDT 2004
On 2004-10-12 at 18:07+0200 Christian Hofer wrote:
> Hi,
>
> having found a bit of time to play with Haskell, I am trying to figure
> out how to enforce strict evaluation.
> I wrote the following program:
>
> main =
> let x = zipWith (+) [5..] [6..]
> in putStrLn $ show $ x `seq` head x
>
> I expected this program not to terminate - because of the seq-Operator,
> but it happily returns 11 in ghc as well as in ghci. What do I make
> wrong?
head is strict in its first argument, so x `seq` head x is
equivalent to head x. seq only evaluates to (w?)hnf. To do
more you would need deepSeq.
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-Cafe
mailing list