[Haskell-cafe] forever function laziness

Bob Ippolito bob at redivi.com
Tue Dec 24 03:05:40 UTC 2013


The best explanation I've found for how Haskell's evaluation works is here:
http://chimera.labs.oreilly.com/books/1230000000929/ch02.html#sec_par-eval-whnf

On Monday, December 23, 2013, Eduardo Sato wrote:

> Hello, guys.
>
> Recently I came across the definition of the function 'forever' on hoogle. I am intrigued that it works.
>
> The recursive definition does make sense to me in a mathematical way, but I can't figure out how it works under the hood in terms of thunks.
>
> To tell you the truth, I don't know how laziness works in general in haskell.
>
> Can someone help me understand how it works in this example, and give some pointers to materials on the subject?
>
> The "tying the knot" article on the wiki is pretty mind bending too.
>
> -- | @'forever' act@ repeats the action infinitely.
>
> forever     :: (Monad m) => m a -> m b
>
> {-# INLINE forever #-}forever a   = let a' = a >> a' in a'
>
> --
>
> Eduardo Sato
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131223/32599d8b/attachment.html>


More information about the Haskell-Cafe mailing list