I had the exact same problem.  It's a consequence of "pattern matching drives evaluation", and indeed that's the lesson I learned from the exercise.  If you match them together at the start, you end up with a recursive call before you've generated the first item in the list.  If you just restructure it so that the second destructure happens after you've produced the first value, everything works.

Julian.


On 18 August 2014 19:22, Curt McDowell <geek@fishlet.com> wrote:
Funny, I was trying the same Homework, implemented interleaveStreams using
the same algorithm you did (taking one item from each stream per recursive
call), and got the same result with the ruler function hanging. It was also
fixed by changing interleaveStreams to take from just one stream per call
and switch back and forth between streams.

This happened even though I implemented my ruler function itself
recursively:

ruler' :: Integer -> Stream Integer
ruler' n = interleaveStreams (streamRepeat n) (ruler' (n + 1))

ruler = ruler' 0

Sorry, but I also don't know why. I speculate that if one were to expand it
out on pencil and paper, they'd find that the interleaved stream somehow
expands at a different rate than the ruler (half or twice).

-Curt


_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners