My function looks like this:
minus :: (Eq a) => [a] -> [a] -> [a] minus [] xs = [] minus (y:ys) xs | y `notElem` xs = y : (minus ys xs) | otherwise = minus ys xs
It can be used as follows:
[99,44,55,22,23423] `minus` [55,22]
with output: [99,44,23423]
I wrote this because I look at the Project Euler 7 issue, and the Eratosthenes sieve seems to be the right tool, and that was, but I continued to read the Wikipedia page and got to the bottom of the Euler sieve.
I tried to copy / paste the code and run it in GHCi, but my version of GHCi does not have a module called Data.OrdList, and I could not find a function called minus in Hoogle.
This is the code from Wikipedia:
import Data.OrdList (minus) primes = euler [2..] euler (p : xs) = p : euler (xs `minus` map (*p) (p : xs))
If I replace my minus function there, I get an error from memory because my function is not lazy.
Is there a way to make a lazy minus function?
Does my minus function use the same thing as the minus function in the Wikipedia article?
list haskell lazy-evaluation
Matt ellen
source share