-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The header code example #46
Comments
The current example as of now is: primes = sieve [2..]
where sieve (p:xs) =
p : sieve [x | x <- xs, x `mod` p /= 0] This is the original example I made and I've restored it. It's inefficient when you run it. But it's very efficient at its purpose, which is to demonstrate:
If you can make an alternative example which satisfies that many criteria for giving a "feel" of the language, please contribute it. I've added a |
I will keep this issue open for future people to see. |
this example is very good. 👍 primes = sieve [2..]
where sieve (p:xs) =
p : sieve [x | x <- xs, x `mod` p /= 0] |
Although I cannot think of a better example right now, I believe this example is misleading. Melissa O'Neil wrote a good article on why: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf You mention that the purpose of the example is to demonstrate, but then list six points on the syntactic construction, which are not essential to the real strength of Haskell. (I do agree upon your seventh point: laziness.) My concern is that this example will lead new Haskell users to believe that Haskell can be understandable or efficient, but never both. Actually, it might lead them to believe that Haskell cannot be efficient... A minor(?) second concern is that this example cannot be entered in the "Try it" REPL directly below. See also this comment on this HN thread. |
"+1" to sebastianv89. This "primes" example is misleading, also for this reason: the subsection heading is "declarative and statically typed", but there are no (visible) types in this code snippet. |
People have been linking this since May last year. I'm aware of the paper. But the example cannot demonstrate anything semantic in a few lines, the point is to show what Haskell feels like on the surface. Nobody's going to actually go run the function. |
At least call the supporting function something else than sieve, because it is not a sieve. Also:
|
For what its worth, it is a sieve, absolutely! Just not the classic sieve, and not as efficient as that one. |
I have mitigated feelings on this example.
The minus:
Of course it's hard to find an example both powerful and beginner-accessible.
It's more chronological (defining sieve first), avoids Also I would add a "what is this?" or "explain me" link explaining what it is (it's not clear to a beginner that this will generate a list of primes) and giving some explanation on how it works. |
A bigger real problem is that as per #87, you can't type it into the repl right below! |
So Ertugrul also suggests we change the name from |
Sure, why not. |
Suggestion: instead of having a single bit of code there with no explanation, imitate the way Racket does this. They have a bit of code with Then we can have a variety of code snippets meant to show off different things; for example (just ideas):
What do people think of this? I think this would give a much more complete view of Haskell as a language and ecosystem. It's a non-trivial amount of work and honestly I don't know how much I can contribute (hopefully some, if people think this is worthwhile), but maybe it's the right way to present these code blocks. |
@gibiansky that was in my original proposal but coming up with that content as you note requires time and thinking not yet spent by anyone yet. |
@chrisdone Ah, makes sense. If there is some time in my life I will tackle this in the next several weeks, but no promises. |
I came here after I saw the discussion in haskell-cafe. I submit these candidates: -- all digit strings (infinite list, shorter lengths first)
digitals = [] : extend digitals
where
base = ['0' .. '3']
extend dss = [ d : ds | ds <- dss, d <- base ]
-- but do you want to demo alphabetical infix?
digitals = [] : ['0' .. '3'] `prepend` digitals
where prepend b dss = [ d : ds | ds <- dss, d <- b ]
-- or do you want to demo user-defined non-alphabetical?
digitals = [] : ['0' .. '3'] +> digitals
where b +> dss = [ d : ds | ds <- dss, d <- b ] |
What about quicksort? I think it's pretty impressive. Also it's general and I think everybody knows quicksort. |
why use this very inefficient solution? I think use the below solution is better ?
may give new Haskell user very bad feel ?
The text was updated successfully, but these errors were encountered: