[Haskell-cafe] loop in C , recursion in haskell

David Roundy droundy at abridgegame.org
Wed Mar 24 09:49:41 EST 2004


On Thu, Mar 25, 2004 at 01:38:44AM +1100, Alex Gontcharov wrote:
> Hi,
> 
> I am new to haskell and would look to write a function equivalent
> to the following loop in C
> 
> int value = 500000;
> int part_stack[4];
> int *part_ptr = part_stack;
> for (; value; value /= 10000)
>       *part_ptr++ = value % 10000;

part_stack :: [Int]
part_stack = [0,50]

Note that I've performed a memoization optimization--this makes the code
both smaller, faster and easier to read! :P

But seriously, the C code doesn't do anything.  Why do you want to
translate it? (Unless it's homework...)
-- 
David Roundy
http://www.abridgegame.org


More information about the Haskell-Cafe mailing list