Last active
December 12, 2015 08:58
-
-
Save WillNess/4747476 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Generating primes in Haskell | |
"I have been learning Haskell over the last few days, through Learn You A Haskell. | |
I've been attempting to complete some Project Euler problems, some of which require | |
primes. However the function I have written to try to generate some (in this case | |
primes below 20000) isn't outputting correctly. When I run it, GHCi returns '[1, ' and | |
seemingly doesn't terminate. The code I am using is: | |
> sieve :: (Integral a) => a -> [a] -> [a] | |
> sieve 20000 list = list | |
> sieve n (x:xs) = sieve (n+1) $ x:(filter (\q -> q `mod` n /= 0) xs) | |
> primesto20000 = sieve 2 [1..20000] | |
"And then I am calling primesto20000. I understand that the function may be inefficient, | |
I am mainly asking for help on syntactic/process errors that I must have made. | |
Thankyou | |
haskell project-euler primes | |
asked Feb 5 at 8:43 | |
bennybdbc" | |
---- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment