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

2010-12-19 Thread ender
Hi all:      I'v been learning haskell for several months, and now I'm trying to write some real word program in haskell, like finding files under one directory or something      My problem is that, I dont know the way of writing a loop in haskell. I searched google and found some code that

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

2010-12-19 Thread Henning Thielemann
On Sun, 19 Dec 2010, ender wrote: do alloca $ \value - do poke value (50::Int) allocaArray 4 $ \part_stack - do alloca $ \part_ptr - do poke part_ptr part_stack let loop = do val - peek value if val == 0 then return () else do p - peek part_ptr

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

2010-12-19 Thread Mihai Maruseac
On Sun, Dec 19, 2010 at 12:27 PM, ender crazyen...@gmail.com wrote: Hi all:      I'v been learning haskell for several months, and now I'm trying to write some real word program in haskell, like finding files under one directory or something      My problem is that, I dont know the way of

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

2010-12-19 Thread Ivan Lazar Miljenovic
On 19 December 2010 21:27, ender crazyen...@gmail.com wrote: Hi all:      I'v been learning haskell for several months, and now I'm trying to write some real word program in haskell, like finding files under one directory or something      My problem is that, I dont know the way of writing a

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

2010-12-19 Thread ender
2010/12/19 Henning Thielemann lemm...@henning-thielemann.de: On Sun, 19 Dec 2010, ender wrote:  do  alloca $ \value - do  poke value (50::Int)  allocaArray 4 $ \part_stack - do  alloca $ \part_ptr - do  poke part_ptr part_stack  let loop = do           val - peek value           if

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

2010-12-19 Thread Lennart Augustsson
Recursion replaces loops. If it needs to be monadic or not depends on what you want to do. On Sun, Dec 19, 2010 at 10:53 AM, ender crazyen...@gmail.com wrote: 2010/12/19 Henning Thielemann lemm...@henning-thielemann.de: On Sun, 19 Dec 2010, ender wrote: do alloca $ \value - do

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

2010-12-19 Thread ender
2010/12/19 Ivan Lazar Miljenovic ivan.miljeno...@gmail.com: On 19 December 2010 21:27, ender crazyen...@gmail.com wrote: Hi all:      I'v been learning haskell for several months, and now I'm trying to write some real word program in haskell, like finding files under one directory or

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

2010-12-19 Thread Ivan Lazar Miljenovic
On 19 December 2010 21:53, ender crazyen...@gmail.com wrote:   Thanks for your quick reply. So recursive and monad is the proper way to simulate loop,right? Well, recursion (either explicitly or implicitly via map, fold, etc.) rather than iteration (i.e. a loop) is the usual approach in

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

2010-12-19 Thread Henning Thielemann
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,