
Hi everybody, I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve and will more likely make people with number theory experience (like me) feel highly irritated rather than fascinated. A real sieve does not only run a million times (!) faster and consumes far less memory, but is also much longer, even in Haskell. Here is a real one: http://lpaste.net/101980 I don't want to make a mountain out of a molehill, but please note: If I'd be new to Haskell, that example would have turned me off, because it would have hurt my ability to take Haskell programmers seriously. You can easily promote your tools when you claim that they can build a car easily, except in reality it's just a toy bicycle. It's the same feeling to cryptographers when people call a regular stream cipher a "one-time pad" and promote it as such. It rings the "this is snake oil!" alarm bell. So I propose to either rename the 'sieve' function to something more appropriate (like `trialDiv`) or replace the example altogether. I would suggest an example that truly shows Haskell's strengths. Trial division search is really just a bad substitute for the more common and equally inappropriate list quicksort example. Greets, Ertugrul

While we're at it, the "foldr (:) [] [1,2,3]" example probably isn't going to cause anyone to give away their worldly possessions and dedicate their lives to haskell.
Tom
El Apr 20, 2015, a las 18:53, Ertugrul Söylemez
Hi everybody,
I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve and will more likely make people with number theory experience (like me) feel highly irritated rather than fascinated. A real sieve does not only run a million times (!) faster and consumes far less memory, but is also much longer, even in Haskell. Here is a real one:
I don't want to make a mountain out of a molehill, but please note: If I'd be new to Haskell, that example would have turned me off, because it would have hurt my ability to take Haskell programmers seriously. You can easily promote your tools when you claim that they can build a car easily, except in reality it's just a toy bicycle.
It's the same feeling to cryptographers when people call a regular stream cipher a "one-time pad" and promote it as such. It rings the "this is snake oil!" alarm bell.
So I propose to either rename the 'sieve' function to something more appropriate (like `trialDiv`) or replace the example altogether. I would suggest an example that truly shows Haskell's strengths. Trial division search is really just a bad substitute for the more common and equally inappropriate list quicksort example.
Greets, Ertugrul _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Are we constraining the examples to not use any external libraries? I can
see why that's a good idea, but it also makes it hard to show something
both pithy and useful.
On Mon, Apr 20, 2015 at 5:22 PM,
While we're at it, the "foldr (:) [] [1,2,3]" example probably isn't going to cause anyone to give away their worldly possessions and dedicate their lives to haskell.
Tom
El Apr 20, 2015, a las 18:53, Ertugrul Söylemez
escribió: Hi everybody,
I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve and will more likely make people with number theory experience (like me) feel highly irritated rather than fascinated. A real sieve does not only run a million times (!) faster and consumes far less memory, but is also much longer, even in Haskell. Here is a real one:
I don't want to make a mountain out of a molehill, but please note: If I'd be new to Haskell, that example would have turned me off, because it would have hurt my ability to take Haskell programmers seriously. You can easily promote your tools when you claim that they can build a car easily, except in reality it's just a toy bicycle.
It's the same feeling to cryptographers when people call a regular stream cipher a "one-time pad" and promote it as such. It rings the "this is snake oil!" alarm bell.
So I propose to either rename the 'sieve' function to something more appropriate (like `trialDiv`) or replace the example altogether. I would suggest an example that truly shows Haskell's strengths. Trial division search is really just a bad substitute for the more common and equally inappropriate list quicksort example.
Greets, Ertugrul _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

The code sample at the top of the page is much debated, and despite the evident problems with it, alternatives proposed have seemed worse for various reasons. There’s an open ticket that discusses this and other issues with that code sample code here: https://github.com/haskell-infra/hl/issues/46 Anybody that wants to make a stab at redesigning the top so that it A) has a code sample demonstrating many language features, B) can’t be poked at for not being the “real” this or that, and C) can be typed or translated directly into the REPL, please have at! -g On April 20, 2015 at 8:48:05 PM, Tikhon Jelvis (tikhon@jelv.is) wrote:
Are we constraining the examples to not use any external libraries? I can see why that's a good idea, but it also makes it hard to show something both pithy and useful.
On Mon, Apr 20, 2015 at 5:22 PM, wrote:
While we're at it, the "foldr (:) [] [1,2,3]" example probably isn't going to cause anyone to give away their worldly possessions and dedicate their lives to haskell.
Tom
El Apr 20, 2015, a las 18:53, Ertugrul Söylemez escribió:
Hi everybody,
I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve and will more likely make people with number theory experience (like me) feel highly irritated rather than fascinated. A real sieve does not only run a million times (!) faster and consumes far less memory, but is also much longer, even in Haskell. Here is a real one:
I don't want to make a mountain out of a molehill, but please note: If I'd be new to Haskell, that example would have turned me off, because it would have hurt my ability to take Haskell programmers seriously. You can easily promote your tools when you claim that they can build a car easily, except in reality it's just a toy bicycle.
It's the same feeling to cryptographers when people call a regular stream cipher a "one-time pad" and promote it as such. It rings the "this is snake oil!" alarm bell.
So I propose to either rename the 'sieve' function to something more appropriate (like `trialDiv`) or replace the example altogether. I would suggest an example that truly shows Haskell's strengths. Trial division search is really just a bad substitute for the more common and equally inappropriate list quicksort example.
Greets, Ertugrul _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

The code sample at the top of the page is much debated, and despite the evident problems with it, alternatives proposed have seemed worse for various reasons.
This really suggests that the code is fine as a little example. Just change the word "sieve" to something else, and everything is fine. =) Greets, Ertugrul

As a replacement, what about:
[ n + 10 | n <- [1..9], odd n ]
Pithy and not equivalent to "id" :P
Tom
El Apr 20, 2015, a las 20:47, Tikhon Jelvis
Are we constraining the examples to not use any external libraries? I can see why that's a good idea, but it also makes it hard to show something both pithy and useful.
On Mon, Apr 20, 2015 at 5:22 PM,
wrote: While we're at it, the "foldr (:) [] [1,2,3]" example probably isn't going to cause anyone to give away their worldly possessions and dedicate their lives to haskell.
Tom
El Apr 20, 2015, a las 18:53, Ertugrul Söylemez
escribió: Hi everybody,
I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve and will more likely make people with number theory experience (like me) feel highly irritated rather than fascinated. A real sieve does not only run a million times (!) faster and consumes far less memory, but is also much longer, even in Haskell. Here is a real one:
I don't want to make a mountain out of a molehill, but please note: If I'd be new to Haskell, that example would have turned me off, because it would have hurt my ability to take Haskell programmers seriously. You can easily promote your tools when you claim that they can build a car easily, except in reality it's just a toy bicycle.
It's the same feeling to cryptographers when people call a regular stream cipher a "one-time pad" and promote it as such. It rings the "this is snake oil!" alarm bell.
So I propose to either rename the 'sieve' function to something more appropriate (like `trialDiv`) or replace the example altogether. I would suggest an example that truly shows Haskell's strengths. Trial division search is really just a bad substitute for the more common and equally inappropriate list quicksort example.
Greets, Ertugrul _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On 21 April 2015 at 10:22,
While we're at it, the "foldr (:) [] [1,2,3]" example probably isn't going to cause anyone to give away their worldly possessions and dedicate their lives to haskell.
I'd hope not: it's a bit hard to write and share awesome Haskell packages without a computer to write and test them on! :p
Tom
El Apr 20, 2015, a las 18:53, Ertugrul Söylemez
escribió: Hi everybody,
I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve and will more likely make people with number theory experience (like me) feel highly irritated rather than fascinated. A real sieve does not only run a million times (!) faster and consumes far less memory, but is also much longer, even in Haskell. Here is a real one:
I don't want to make a mountain out of a molehill, but please note: If I'd be new to Haskell, that example would have turned me off, because it would have hurt my ability to take Haskell programmers seriously. You can easily promote your tools when you claim that they can build a car easily, except in reality it's just a toy bicycle.
It's the same feeling to cryptographers when people call a regular stream cipher a "one-time pad" and promote it as such. It rings the "this is snake oil!" alarm bell.
So I propose to either rename the 'sieve' function to something more appropriate (like `trialDiv`) or replace the example altogether. I would suggest an example that truly shows Haskell's strengths. Trial division search is really just a bad substitute for the more common and equally inappropriate list quicksort example.
Greets, Ertugrul _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

On 21 April 2015 at 08:53, Ertugrul Söylemez
Hi everybody,
I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve and will more likely make people with number theory experience (like me) feel highly irritated rather than fascinated. A real sieve does not only run a million times (!) faster and consumes far less memory, but is also much longer, even in Haskell. Here is a real one:
I don't want to make a mountain out of a molehill, but please note: If I'd be new to Haskell, that example would have turned me off, because it would have hurt my ability to take Haskell programmers seriously. You can easily promote your tools when you claim that they can build a car easily, except in reality it's just a toy bicycle.
It's the same feeling to cryptographers when people call a regular stream cipher a "one-time pad" and promote it as such. It rings the "this is snake oil!" alarm bell.
So I propose to either rename the 'sieve' function to something more appropriate (like `trialDiv`) or replace the example altogether. I would suggest an example that truly shows Haskell's strengths. Trial division search is really just a bad substitute for the more common and equally inappropriate list quicksort example.
My understanding is that it *is* a sieve, just not the Sieve of Eratosthenes (because it's a bit hard to fit that into that small little sample box up the top of the page :p). -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve [...]
My understanding is that it *is* a sieve, just not the Sieve of Eratosthenes (because it's a bit hard to fit that into that small little sample box up the top of the page :p).
The main characteristic of a sieve is that it does not divide and that it eliminates all multiples of a prime without a test. Check one bit, eliminate many. In general if you see any of `mod`, `div` and friends, then it's very unlikely to be a sieve. The only real advantage of the example is that it uses shared primes to use trial division only against primes (instead of probable primes). This gives a slight speedup at the expense of needing a lot of memory. Greets, Ertugrul

If you want to use bit fiddly mutable vector stuff to make the classic
Sieve of Eratosthenes fast and compact, I think it makes a lot of sense to
use the bitvec package instead of doing the bit fiddling by hand.
On the other hand, I think the O'Neill prime sieve makes an excellent
example, much prettier than a mutable-vector-based sieve. Her paper is at
https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf and her actual
implementation (much better than the one described directly in the paper)
is at
https://hackage.haskell.org/package/NumberSieves/docs/Math-Sieve-ONeill.html
. It can be optimized in various ways, most obviously by specializing from
Integral to Word, but probably also by switching from a tree-based heap to
one based on a mutable vector. I'm not sure how a really carefully
optimized version would compare to Eratosthenes.
On Mon, Apr 20, 2015 at 9:11 PM, Ertugrul Söylemez
I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve [...]
My understanding is that it *is* a sieve, just not the Sieve of Eratosthenes (because it's a bit hard to fit that into that small little sample box up the top of the page :p).
The main characteristic of a sieve is that it does not divide and that it eliminates all multiples of a prime without a test. Check one bit, eliminate many.
In general if you see any of `mod`, `div` and friends, then it's very unlikely to be a sieve. The only real advantage of the example is that it uses shared primes to use trial division only against primes (instead of probable primes). This gives a slight speedup at the expense of needing a lot of memory.
Greets, Ertugrul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

So how about this:
Leave the example. But change the blurb to say:
This is inspired by the Sieve of Eratosthenes. For a true
Sieve of Eratosthenes, see [link to O'Neil].
On Tue, Apr 21, 2015 at 6:43 AM, David Feuer
If you want to use bit fiddly mutable vector stuff to make the classic Sieve of Eratosthenes fast and compact, I think it makes a lot of sense to use the bitvec package instead of doing the bit fiddling by hand.
On the other hand, I think the O'Neill prime sieve makes an excellent example, much prettier than a mutable-vector-based sieve. Her paper is at https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf and her actual implementation (much better than the one described directly in the paper) is at https://hackage.haskell.org/package/NumberSieves/docs/Math-Sieve-ONeill.html . It can be optimized in various ways, most obviously by specializing from Integral to Word, but probably also by switching from a tree-based heap to one based on a mutable vector. I'm not sure how a really carefully optimized version would compare to Eratosthenes.
On Mon, Apr 20, 2015 at 9:11 PM, Ertugrul Söylemez
wrote: I'd like to note that the prime "sieve" example that is sitting at the top of the homepage is not a real sieve [...]
My understanding is that it *is* a sieve, just not the Sieve of Eratosthenes (because it's a bit hard to fit that into that small little sample box up the top of the page :p).
The main characteristic of a sieve is that it does not divide and that it eliminates all multiples of a prime without a test. Check one bit, eliminate many.
In general if you see any of `mod`, `div` and friends, then it's very unlikely to be a sieve. The only real advantage of the example is that it uses shared primes to use trial division only against primes (instead of probable primes). This gives a slight speedup at the expense of needing a lot of memory.
Greets, Ertugrul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Leave the example. But change the blurb to say: This is inspired by the Sieve of Eratosthenes. For a true Sieve of Eratosthenes, see [link to O'Neil].
Unfortunately trial division is in no way inspired by the SoE. It's about the most bruteforcy way to find primes. Basically all it does is to perform a full primality test for every single candidate. The only advantage of the example code is that it uses laziness and sharing to keep a list of the primes found so far to make this trial division slightly less expensive. In fact it can be improved quadratically and still wouldn't be a sieve. On my current machine in 1 second the following code finds the first 60000 primes while the homepage example finds only 3700 primes, both specialised to [Int]: primes = 2 : filter isPrime [3..] where isPrime x = all (\p -> mod x p /= 0) . takeWhile (\p -> p*p <= x) $ primes The SoE on the other hand exploits the global structure of the distribution of a prime's multiples. Without any division at all it simply deduces that after each crossing operation the smallest remaining integer *must* be prime. This is pretty much the same improvement the quadratic sieve makes to Dixon's factoring method and the number field sieve makes to the index calculus method. It gets rid of primality tests and uses the distributions of multiples. Thus it finds lots and lots of relations in one go rather than testing every single relation. It would be equally wrong to call Dixon's method or index calculus sieves. How about simply changing `sieve` to `trialDiv`? It's not that I don't like the given example, because it gives a very small use case for laziness that is difficult enough to reproduce in an eagerly evaluated language. And with the new name for the local function it stops turning the stomach of a number theoretician. Greets, Ertugrul

I think the code sample should be replaced with a number of different code
samples, demonstrating different things. Then we don't have to try to fit
all the syntax into one bit of code, and so we can avoid using a fake sieve
entirely. See the way Racket does their code demos:
http://racket-lang.org/
I also posted this for discussion on the Github issue:
https://github.com/haskell-infra/hl/issues/46
-- Andrew
On Tue, Apr 21, 2015 at 11:32 AM, Ertugrul Söylemez
Leave the example. But change the blurb to say: This is inspired by the Sieve of Eratosthenes. For a true Sieve of Eratosthenes, see [link to O'Neil].
Unfortunately trial division is in no way inspired by the SoE. It's about the most bruteforcy way to find primes. Basically all it does is to perform a full primality test for every single candidate. The only advantage of the example code is that it uses laziness and sharing to keep a list of the primes found so far to make this trial division slightly less expensive.
In fact it can be improved quadratically and still wouldn't be a sieve. On my current machine in 1 second the following code finds the first 60000 primes while the homepage example finds only 3700 primes, both specialised to [Int]:
primes = 2 : filter isPrime [3..] where isPrime x = all (\p -> mod x p /= 0) . takeWhile (\p -> p*p <= x) $ primes
The SoE on the other hand exploits the global structure of the distribution of a prime's multiples. Without any division at all it simply deduces that after each crossing operation the smallest remaining integer *must* be prime.
This is pretty much the same improvement the quadratic sieve makes to Dixon's factoring method and the number field sieve makes to the index calculus method. It gets rid of primality tests and uses the distributions of multiples. Thus it finds lots and lots of relations in one go rather than testing every single relation. It would be equally wrong to call Dixon's method or index calculus sieves.
How about simply changing `sieve` to `trialDiv`? It's not that I don't like the given example, because it gives a very small use case for laziness that is difficult enough to reproduce in an eagerly evaluated language. And with the new name for the local function it stops turning the stomach of a number theoretician.
Greets, Ertugrul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Nobody wants to see a number theory example anyway. I agree with Andrew that racket's system with multiple demos is nice, but also think each demo is much more interesting because they're problems you're more likely to run into day to day. On Tue, Apr 21, 2015 at 6:42 PM, Andrew Gibiansky < andrew.gibiansky@gmail.com> wrote:
I think the code sample should be replaced with a number of different code samples, demonstrating different things. Then we don't have to try to fit all the syntax into one bit of code, and so we can avoid using a fake sieve entirely. See the way Racket does their code demos:
I also posted this for discussion on the Github issue:
https://github.com/haskell-infra/hl/issues/46
-- Andrew
On Tue, Apr 21, 2015 at 11:32 AM, Ertugrul Söylemez
wrote: Leave the example. But change the blurb to say: This is inspired by the Sieve of Eratosthenes. For a true Sieve of Eratosthenes, see [link to O'Neil].
Unfortunately trial division is in no way inspired by the SoE. It's about the most bruteforcy way to find primes. Basically all it does is to perform a full primality test for every single candidate. The only advantage of the example code is that it uses laziness and sharing to keep a list of the primes found so far to make this trial division slightly less expensive.
In fact it can be improved quadratically and still wouldn't be a sieve. On my current machine in 1 second the following code finds the first 60000 primes while the homepage example finds only 3700 primes, both specialised to [Int]:
primes = 2 : filter isPrime [3..] where isPrime x = all (\p -> mod x p /= 0) . takeWhile (\p -> p*p <= x) $ primes
The SoE on the other hand exploits the global structure of the distribution of a prime's multiples. Without any division at all it simply deduces that after each crossing operation the smallest remaining integer *must* be prime.
This is pretty much the same improvement the quadratic sieve makes to Dixon's factoring method and the number field sieve makes to the index calculus method. It gets rid of primality tests and uses the distributions of multiples. Thus it finds lots and lots of relations in one go rather than testing every single relation. It would be equally wrong to call Dixon's method or index calculus sieves.
How about simply changing `sieve` to `trialDiv`? It's not that I don't like the given example, because it gives a very small use case for laziness that is difficult enough to reproduce in an eagerly evaluated language. And with the new name for the local function it stops turning the stomach of a number theoretician.
Greets, Ertugrul
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

If you want to use bit fiddly mutable vector stuff to make the classic Sieve of Eratosthenes fast and compact, I think it makes a lot of sense to use the bitvec package instead of doing the bit fiddling by hand.
Indeed. However, the purpose of this code is to outperform the equally well optimised version in C and compiled with GCC or Clang. That's also the sole reason why I used TH to precompute a value that should never have been noticable in the first place. The code was written for GHC 7.6. More recent versions might no longer require TH to outperform GCC/Clang. Greets, Ertugrul
participants (9)
-
amindfv@gmail.com
-
Andrew Gibiansky
-
Curtis Gagliardi
-
David Feuer
-
Ertugrul Söylemez
-
Gershom B
-
Ivan Lazar Miljenovic
-
Tikhon Jelvis
-
Yitzchak Gale