[Haskell-cafe] how to write a loop in haskell way

Henning Thielemann lemming at henning-thielemann.de
Sun Dec 19 12:10:07 CET 2010


On Sun, 19 Dec 2010, ender wrote:

> Hi Henning:
>   Thanks for your quick reply. So recursive and monad is the proper
> way to simulate loop,right?

I kept close to your suggestion, but avoiding monads, especially IO, is a 
good idea. If you do not need low-level memory access with peek and poke, 
better use lists or arrays (high level) or StorableVector (more efficient 
but not as flexible as array).

http://www.haskell.org/haskellwiki/Avoiding_IO

Avoiding explicit recursion is also a good thing - using too much (tail) 
recursive function calls ends up looking like code with lots of GOTOs. 
Better use higher order functions.

http://www.haskell.org/haskellwiki/Haskell_programming_tips#Avoid_explicit_recursion



More information about the Haskell-Cafe mailing list