diff --git a/haskell/8_prime_number.hs b/haskell/8_prime_number.hs new file mode 100644 index 0000000..29849ae --- /dev/null +++ b/haskell/8_prime_number.hs @@ -0,0 +1,8 @@ +module IsPrime where + +isPrime :: Integer -> Bool +isPrime x + | x `elem` [2, 3, 5, 7] = True + | x < 2 || even x = False + | otherwise = not $ any (\n -> x `rem` n == 0) [3, 5..last] + where last = (round . sqrt . fromIntegral) x