I believe you wanted to write filter with a do-notation. You could just add a do just after the filter ls indx =. However, this code being pure (i.e. non monadic), I would recommend this syntax:
primeSieve :: Int -> [Int] -- Returns a list of primes up to upperbound
primeSieve upperbound = filter [2..upperbound]
where
filter ls indx =
let divisor = (ls!!indx)
filtered = [x | x <- ls, x `mod` divisor /= 0]
in if divisor*divisor >= last filtered
then filtered
else filter filtered (indx+1)
... but your code gives me the following error:
<file>:13:25:
Couldn't match expected type `[Int]'
with actual type `Int -> [Int]'
Probable cause: `filter' is applied to too few arguments
In the expression: filter [2 .. upperbound]
In an equation for `primeSieve':
primeSieve upperbound
= filter [2 .. upperbound]
where
filter ls indx
= let ...
in
if divisor * divisor >= last filtered then
filtered
else
filter filtered (indx + 1)
Failed, modules loaded: none.
I think you meant to pass 0 as a second argument to filter:
primeSieve :: Int -> [Int] -- Returns a list of primes up to upperbound
primeSieve upperbound = filter [2..upperbound]
where
filter ls indx =
let divisor = (ls!!indx)
filtered = [x | x <- ls, x `mod` divisor /= 0]
in if divisor*divisor >= last filtered
then filtered
else filter filtered (indx+1)