Haskellで数値が入力された後、次に近い素数を計算しようとしています.2つの関数isPrime
をコーディングしました.nextPrime
これが私のコードです:
isPrime :: Int -> Bool
isPrime x | x < 2 = False
| otherwise = prime (2:[3,4..(x-1)])
where
prime (y:z)
| x < y ^ 2 = True
| x `mod` y == 0 = False
| otherwise = prime z
nextPrime :: Int -> Int
nextPrime n | isPrime n == True = n
| otherwise = nextPrime n
where
n = n + 1
私が抱えている問題は、実行時にこのエラーが発生することです: * Exception: "<<"loop">>"
よくわからないのですが、無限ループですか?