とあるプログラマの変遷
level1
ループ最高!ループほど明確なものはないだろう。
int fact(int n){ int result = 1; for(int i = 1 ; i <= n ; i++){ result *= i; } return result; }
level3
foldl最高!!!
いちいち再帰関数を書くのは面倒。mapとfoldlを組み合わせて書くべきだ。
fact n = foldl (*) 1 [1..n] -- あるいはfact n = product [1..n]