From: Florian Frank Date: 2005-10-20T05:34:49+09:00 Subject: Re: Functional with Ruby Louis J Scoras wrote: >Yes, it is ultimately defined recursively, but the complexity is pushed down >into the fold* functions. Granted it's a pretty simple recursion, but the >point still holds. > > I think the point is, that you can use foldr, a function that is defined in Haskell only in terms of recursion. But Ruby's inject isn't defined in Ruby, it's a method of Array (a stateful data structure) written in C and it is actually implemented iterative. The Ruby version isn't really functional, it's only very similar, while the Haskell foldr is a recursivley defined function. So if you want to play with functional style programming in Ruby, using Array#inject is a bit fishy. On the other hand, if you want to write a reasonable fast program in Ruby, I would avoid recursion as much as possible, go for iteration, and concentrate on using methods implemented in C instead. But it seemed to me, that the OP was more interested in learning about functional programming (using Ruby as well as Haskell), than writing fast programs. -- Florian Frank