<div dir="ltr">I will suggest an analogy to a similar (but simpler) situation.<div><br></div><div>Suppose you are adding up some numbers.</div><div><br></div><div>foo = let { x = 3; y = 4; z = 5 } in x + y + z</div><div><br>
</div><div>That pattern only works if you know in advance how many numbers you are going to add.</div><div><br></div><div>Otherwise, you need a function that works on a whole list of numbers:</div><div><br></div><div>sum = foldr (+) 0</div>
<div><br></div><div>So...the short answer to your question is: use recursion. The better answer is: use library functions that do the recursion for you. You might want to look at foldM:</div><div><br></div><div><a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:foldM">http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:foldM</a><br>
</div><div><br></div><div>-Karl</div></div>