[Haskell-cafe] laziness blowup exercise

Bas van Dijk v.dijk.bas at gmail.com
Thu Jul 16 15:35:35 EDT 2009

On Thu, Jul 16, 2009 at 8:22 PM, Thomas Hartman<tphyahoo at gmail.com> wrote:
> I played with this a bit, and ok, it seems the difference between
> iterate' and iterate'' is
> h _ = 2
> tit' = head . drop 1 . iterate' h $ undefined
> tit'' = head . drop 1 . iterate'' h $ undefined

Exactly, iterate' first evaluates 'undefined' which is undefined.
iterate'' returns 'undefined : iterate'' h 2'. Which then evaluates
to: 'undefined : 2 : iterate'' h 2'.

So both iterates are strict in their accumulator. They differ in when
they force it. The former is more strict in that it forces its
accumulator on entry while the latter is more lazy by first returning
the accumulator and later forcing it.

>> (Bas wishes for a type system that can express the different
> strictness properties of these functions...)
> Is this being worked on?

I have no idea.



More information about the Haskell-Cafe mailing list