[Haskell-cafe] forever function laziness

Eduardo Sato eduardo.sato at gmail.com
Tue Dec 24 02:02:23 UTC 2013

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/20131224/bb26b036/attachment.html>

More information about the Haskell-Cafe mailing list