我正在尝试编写一个返回给定数字以下所有素数列表的过程。
例如:
Prelude>primes 8
[2,3,5,7]
当我尝试加载文件时,Parse error in pattern Failed, modules loaded: none.
如果有人能指出我正确的方向,我将不胜感激。
primes :: Int -> [Int]
primes x < 2 = []
primes x | isPrime x == True = primes (x - 1) ++ x
| otherwise = primes (x - 1)
isPrime :: Int -> Bool
isPrime x | x < 2 = False
| x == 2 || x == 3 = True
| divEven x == True = False
| divOdd x 3 == True = False
| otherwise = True
divEven :: Int -> Bool
divEven x | mod x 2 == 0 = True
| otherwise = False
divOdd :: Int Int -> Bool
divOdd x num | mod x num == 0 == True
| num <= x/2 = divOdd x (num + 2)
| otherwise = False