Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1 +1 @@
factorial n = foldl (*) 1 [1..n]
factorial = product . enumFromTo 1

View file

@ -1 +1 @@
factorials = scanl (*) 1 [1..]
factorial n = foldl (*) 1 [1..n]

View file

@ -1,3 +1 @@
factorial :: Integral -> Integral
factorial 0 = 1
factorial n = n * factorial (n-1)
factorials = scanl (*) 1 [1..]

View file

@ -1,5 +1,3 @@
fac n
| n >= 0 = go 1 n
| otherwise = error "Negative factorial!"
where go acc 0 = acc
go acc n = go (acc * n) (n - 1)
factorial :: Integral -> Integral
factorial 0 = 1
factorial n = n * factorial (n-1)

View file

@ -0,0 +1,5 @@
fac n
| n >= 0 = go 1 n
| otherwise = error "Negative factorial!"
where go acc 0 = acc
go acc n = go (acc * n) (n - 1)

View file

@ -0,0 +1,8 @@
{-# LANGUAGE PostfixOperators #-}
(!) 0 = 1
(!) n = n * ((n-1)!)
main = do
print (5!)
print ((4!)!)