[Haskell-beginners] Factorials using foldx

Paul Johnston paul.a.johnston at manchester.ac.uk
Thu Aug 7 10:16:04 EDT 2008

Hi (First question so be gentle)!
Just started to look at Haskell and I was wondering about various versions of calculating factorials.

If I have 

facr 0 = 1
facr n = foldr (*) 1 [1..n]

facl 0 = 1
facl n = foldl (*) 1 [1..n]

Is there any difference in efficiency, I remember reading it is better to count down than to count up but left to right or right to left :-)

Cheers Paul

Paul Johnston
Humanities Development Team
Room 2.12
Bridgeford Street Building
Manchester University
Tel 0161 275 1396
Mail Paul.Johnston at manchester.ac.uk
Web http://web-1.humanities.manchester.ac.uk/prjs/mcasspj/
How to shoot yourself in the foot 
% ls
             foot.c foot.h foot.o toe.d toe.o
            %rm* .o
            rm:.o no such file or directory

More information about the Beginners mailing list