Posts

Showing posts with the label scala

Why doesn't Haskell need Trampolining?

18 5 As Scala developer learning the IO Monad, and therefore technicalities of Trampolining in general that are necessary for recursion where tail call optimization is not possible, I wonder how Haskell seems to natively avoid it. I get that Haskell is a lazy language, however I wonder if someone could elaborate a bit further. For instance, why doesn't ForeverM stackoverflow in scala? Well, I can answer for trampoline, and I can find the actual code that does that in libraries and blogs. I actually implemented a basic trampoline myself to learn. How does it happens in Haskell? Is there a way to unpack the laziness a bit, give some pointers, and maybe documentation that would help in understanding it better? sealed trait IO[A] { ..... def flatMap[B](f: A =...