Permalink
Browse files

add Math.Compute

  • Loading branch information...
1 parent dea8c75 commit 07655d1f1f12714c89e1f480c3ea067769547f80 @lilydjwg committed Apr 23, 2012
Showing with 19 additions and 0 deletions.
  1. +19 −0 lib/Math/Compute.hs
View
@@ -0,0 +1,19 @@
+module Math.Compute (
+ primes,
+ isPrime,
+ factorial,
+) where
+
+import Control.Monad
+import Control.Monad.Instances
+
+isPrime :: Integral a => a -> Bool
+primes :: Integral a => [a]
+isPrime x = let prime_useful = takeWhile (\y -> y*y <= x) primes
+ in all (\y -> x `mod` y /= 0) prime_useful
+primes = 2 : filter isPrime [3, 5..]
+
+factorial :: Integer -> Integer
+factorial 0 = 1
+factorial 1 = 1
+factorial n = n * (factorial (n-1))

0 comments on commit 07655d1

Please sign in to comment.