Posts

Showing posts with the label lazy-evaluation

What does seq actually do in Haskell?

17 4 From Real World Haskell I read It operates as follows: when a seq expression is evaluated, it forces its first argument to be evaluated, then returns its second argument. It doesn't actually do anything with the first argument: seq exists solely as a way to force that value to be evaluated. where I've emphasised the then because to me it implies an order in which the two things happen. From Hackage I read The value of seq a b is bottom if a is bottom, and otherwise equal to b . In other words, it evaluates the first argument a to weak head normal form (WHNF). seq is usually introduced to improve performance by avoiding unneeded laziness. A note on evaluation order: the expression seq a b does not guarantee that a will be evaluated before b ...