3 ms·
In Haskell: factorial n = product [1..n] Also polymorphic to all of those types and results in 1 for negatives. If you want the polymorphic "memoizing ve
by Peaker 16y ago
In Haskell:
factorial n = product [1..n]
Also polymorphic to all of those types and results in 1 for negatives.
If you want the polymorphic "memoizing version":
factorials = scanl (*) 1 [0..]
factorial = (factorials !!)
- jcromartie 16y agoHaskell wins!
- eru 16y agoNo, see: http://www.willamette.edu/~fruehr/haskell/evolution.html http://www.willamette.edu/~fruehr/haskell/evolution.html aka "How not to write factorial in Haskell".