[Haskell-beginners] How does forever works ?
Olivier Revollat
revollat at gmail.com
Mon Jul 9 11:31:07 UTC 2018
>From what I understand, this code
main = forever $ do
putStrLn "OK !"
is equivalent to this one :
main = do
putStrLn "OK !"
main
In the second case, it's a simple recursion, so far so good ... but when I
look at the implementation of "forever" i can't wrap my head around :
http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever
forever <http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever>
a <http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327090>
= let a' <http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327091>
= a <http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327090>
*> <http://hackage.haskell.org/package/base-4.11.1.0/docs/src/GHC.Base.html#%2A%3E>
a' <http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327091>
in a' <http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#local-6989586621679327091>
How does this works ? How does this make an infinite loop ?
I understand that *> discard his right argument but it doesn't help me
understand how forever implement an infinite loop ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180709/b9fbb3d7/attachment.html>
More information about the Beginners
mailing list