[Haskell-cafe] Lazy Evaluation in Monads

Scott Lawrence bytbox at gmail.com
Tue May 31 23:09:00 CEST 2011


Apparently:

Prelude> let r = (fmap (1:) r) :: IO [Integer]
Prelude> fmap (take 5) r
*** Exception: stack overflow

Thanks - I'll just have to stay out of IO for this, then.

On Tue, May 31, 2011 at 17:05, Stephen Tetley <stephen.tetley at gmail.com> wrote:
> 2011/5/31 Scott Lawrence <bytbox at gmail.com>:
>
>> Evaluation here also doesn't terminate (or, (head $ unfoldM (return .
>> head)) doesn't), although I can't figure out why. fmap shouldn't need to
>> fully evaluate a list to prepend an element, right?
>
> I'm afriad fmap doesn't get to choose - if the monad is strict then
> both definitions are equivalent (probably...).
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Scott Lawrence



More information about the Haskell-Cafe mailing list