On Thu, 18 Feb 1999, Jason Stokes wrote:
> Aha. A question I know how to answer.
>
> Because Haskell is a pure functional language, it doesn't have looping
> constructs or any other explicit imperative features (ignoring "main" for the
> moment.) Standard Haskell style is to define the function recursively with,
> say g', and then define g in terms of g', passing the initial "seed" value as
> an argument to g'. This isn't bad style, it's normal and quite clear.
This is correct in spirit, but it's helpful to distinguish between having
a loop which is a computation and a termination conditon, and the much
more extensive use of loops in imperative programs to cycle through
indices for one reason or another, e.g., array modification.
It's not repeating a computation over many values (which could be still
reasonably be called `looping') that's imperative but using imperative
update of the data structures as you're doing this repeating. For example,
the standard prelude has the standard function until
until :: (a -> Bool) -> (a -> a) -> a -> a
for the first kind of looping, e.g., a Newton-Raphson style root finder.
This is still purely functional because it's just values in and result
out. But for the second type of looping which is much, much more common,
Jason is right that recursion is the way to think about things.
___cheers,_dave_________________________________________________________
email: [EMAIL PROTECTED] "He believed in substitions
www.cs.bris.ac.uk/~tweed/pi.htm sometimes things just
work tel: (0117) 954-5253 just happen" -- Terry Pratchett, Jingo