trying to work out why this won't compile? I just posted a similar issue about haskell's 'where' syntax.
primeFactors :: Int -> [Int]
primeFactors x = genPrimes x []
where
genPrimes x xs
|x == 0 = []
|isPrime x = x : genPrimes (x - 1) xs
|otherwise = genPrimes (x - 1) xs
I'm getting a parse error on input '|'
The 'isPrime' function is defined here, and holds a similar structure and functions fine, what's the syntactic issue with 'primeFactors'?
isPrime :: Int -> Bool
isPrime a = go a (a - 1)
where
go a b
|a == 1 || b == 1 = True
|a `mod` b == 0 = False
|otherwise = go a (b - 1)
Thanks.
primeFactorsworks right -primeFactors 5would return[5,3,2], you never change thexsinside to anything different then[], ...