5 ms·
It does miss a trivial optimization. For example, fac n = product [1..n] can be replaced with fac n = product [2..n] and will still do the right thi
by wging 13y ago
It does miss a trivial optimization. For example,
fac n = product [1..n]
can be replaced with
fac n = product [2..n]
and will still do the right thing for n == 0, n == 1. Saves you a multiplication!
- lelf 13y agoYou are right! But let's do it the proper way {-# RULES "product/1" forall x. product [1..x] = product [2..x] #-} fac n = product [1..n]