I am trying to achieve prime number through recursion, I know how to do it with list.
Type error in function binding
primes :: [Int]
primes = sieve [2..10]
sieve[] = []
sieve(x:xs) = x : sieve (filter p [xs])
where p x = xs `mod` x > 0
I also tried it doing with map and got type error in application
primes :: [Int]
primes = sieve [2..10]
sieve[] = []
sieve(x:xs) = x : sieve (map (`mod` x > 0) [xs])
I am trying to achieve something similar what we do with list
sieve (a:x) = a:sieve [y| y<-x, y`mod`a > 0]
You can’t
moda list with an integer.You probably meant
Notice I also had to change the parameter to
yso it won’t shadow thexfrom the pattern on the previous line.Also,
filter p [xs]should befilter p xs.