[Haskell-cafe] Is it possible to make lazy combinators for IO?

David Turner dct25-561bs at mythic-beasts.com
Mon Apr 18 20:47:09 UTC 2016


You can't know that the final result of the computation (x `seq` (3:...))
will begin with 3, because sometimes it doesn't! More specifically, it
diverges (without yielding the 3) if x diverges.

I don't think this is anything special about mfix: (let x = x `seq` 3:...
in x) also diverges for the same reason.

Hope that helps,

David
On 18 Apr 2016 21:19, "David Feuer" <david.feuer at gmail.com> wrote:

> If
>
> f :: a -> IO a
>
> for some a, and I want to use
>
> mfix f
>
> then f must not inspect its argument in any way, or the computation
> will get stuck. In some cases, this seems a bit harsh. For example,
>
> mfix (\x -> fmap (3 :) (x `seq` readLn))
>
> looks perfectly reasonable. There is no need to inspect the return []
> action to know that the final result of the computation will begin
> with 3:. Is there a lazy IO mapping function somewhere that can work
> such magic?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160418/7fbfdde5/attachment.html>


More information about the Haskell-Cafe mailing list