[Haskell-beginners] Data.Stream interleave implementation question

Bryan Brady bryan.brady at gmail.com
Wed Feb 12 12:49:04 UTC 2014


Thanks Isaac! It never crossed my mind that the problem was on the left
hand side.

On Wed, Feb 12, 2014 at 3:36 AM, Isaac Dupree <
ml at isaac.cedarswampstudios.org> wrote:

> [...]
> In this situation, if interleaveStreams evaluates its second argument
> before returning any work, it will never be able to return.  Happily, the
> outer Cons of the result does not depend on the second argument.  I can fix
> the issue just by making the second argument be pattern-matched lazily
> (with ~, i.e. only as soon as any uses of the argument in the function are
> evaluated):
>
interleaveStreams (Cons a as) ~(Cons b bs) = Cons a (Cons b
> (interleaveStreams as bs))
>
>
> So that's what the ~ does... :)


I'm not sure whether there's a practical difference between these and
> Data.Stream's definition.  Actually, I think they turn out to do exactly
> the same thing...
>
Yes, they do. I used the solution in Data.Stream to fix mine, though I
didn't recognize the true source of the problem until you pointed it out.
Thanks again!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140212/86de6862/attachment.html>


More information about the Beginners mailing list