Way back in 2000, DaveKern showed me Haskell, and I dinked around with it for a little bit, but I didn't get it. Now PUGS, an implementation of perl6 in Haskell, has come along and re-opened my eyes. It's certainly changed how I view Perl (and unfortunately, I can't wait for perl6 now).
Were you to write your basic summation subroutine in perl, you could make it look functional, and it would be:
sub summation { $_[0] <= 0 and return 0; $_[0] > 0 and return $_[0] + summation($_[0] - 1); }The problem is that perl5 doesn't convert the tail recursion into an iteration for you, so while the above is a very legible perl5 program, it very quickly goes to p00 (at 900000 or higher for my poor little box). So, perl5 implementations are usable only if they are iterative, like:
sub summation_iterative { my $ret; my $i; while ( $i <= $_[0] ) { $ret += $i; $i++; } return $ret; }The bad thing is that the iterative implementation is longer and less legible than the functional implementation because of the iterative approach's variable work. The functional approach just lists its two cases and how it deals with them. If you grok recursion, then the functional is more legible. And since I want to write legible code, I'll be happier when perl6 arrives. Hopefully that won't be tooooo long. ;)