Skip to content
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

First code example doesn't even work #87

Open
Macil opened this issue Feb 17, 2015 · 10 comments
Open

First code example doesn't even work #87

Macil opened this issue Feb 17, 2015 · 10 comments

Comments

@Macil
Copy link

Macil commented Feb 17, 2015

(Apologies if this is the wrong repo entirely. I scoured the Haskell website for any "report a bug" links but couldn't find any.)

  1. I browse to https://www.haskell.org/
  2. At the top right it shows me an example of some nice "Declarative, statically typed code" which really does look pretty nice.
primes = sieve [2..] 
  where sieve (p:xs) = 
          p : sieve [x | x <- xs, x `mod` p /= 0]
  1. I notice a "Try it" section. I decide to play around with that very first example:
Type Haskell expressions in here.
λ prime = sieve [2..]
<hint>:1:7: parse error on input `='
λ  

Huh, maybe it tries to interpret each line individually. What if I do it all on one line?

λ primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p /= 0]
<hint>:1:8: parse error on input `='
λ  

My first impression is that I'll come back in a few years when Haskell is less buggy.

@gbaz
Copy link

gbaz commented Feb 17, 2015

Hi Chris!

A) this is an issue with the example code being designed to work in a file, not in the "try it section". So Haskell isn't buggy in this regard, we just don't have a good explanation that that example doesn't work with our "try it" tool. So I hope you don't still have that impression :-)

B) This is one of many reports that the section you find confusing is in fact terribly confusing for exactly the reason you've given. Thanks for finding a place to file a ticket! This underlines that we really do need to clear this problem up.

@Macil
Copy link
Author

Macil commented Feb 17, 2015

Thanks for the response!

I will admit that that was only my immediate impression with the site, and that I'm sure I'm doing something wrong and missing some certain concept about a different between the REPL and the compiler. I've heard a lot of good things about Haskell already and am planning to push past this anyway, but I'm worried that there are many users who will in fact stop right at this exact point.

Maybe the code example at the top right should be changed to be something that works in the REPL, or the REPL should recognize this type of warning and suggest the "let" statement or whatever it is that gets it to work in the REPL.

@gbaz
Copy link

gbaz commented Feb 17, 2015

Here is one silly proposal to fix this -- we pattern match on the "try it" box to see if someone is likely trying to do the primes example, then pop up a special message saying "the primes example is suited for writing in a file. at the console, we use different syntax, like so"

and then provide let primes = sieve [2..]; sieve (p:xs) = p : sieve [ x | x <- xs, xmodp /=0] in primes or something.

@gbaz
Copy link

gbaz commented Feb 17, 2015

Alternately we replace the primes example with 2-3 one liners that each do work in the console!

foldr (*) 1 [1..10], [x | x <- [1..10], mod x 2 /= 0], let fibs = 0:1:zipWith (+) fibs (tail fibs) in fibs, let pgen (p:xs) = p : pgen [x|x <- xs, mod x p > 0] in pgen [2..] or the like.

And then make those clickable to go into the console too!

@gbaz
Copy link

gbaz commented Feb 17, 2015

(p.s. i see our comments crossed during writing -- glad to see we've got the same ideas :-) )

@chrisdone
Copy link
Member

Alternately we replace the primes example with 2-3 one liners that each do work in the console!

I like this idea.

@chrisdone
Copy link
Member

But I'd prefer to make it support fun/pat declarations. I see people writing "x = foo" in the REPL all the time. It's possible for tryhaskell to accept a list of declarations and nest them as let. Similar to the IO support, whenever it receives a fun/pat declaration it can reply with a context including that to be included next time an expression is evaluated.

@chrisdone
Copy link
Member

A request like this:

writeFile "/foo" "hello"
[[],{"/functions":"You can also check out removeFile, writeFile, appendFile",
"/files":"Your file system changes will stick around in your browser's localstorage!",
"/welcome":"Welcome to your mini filesystem! Try playing with
 this function: getDirectoryContents","/foo":"hello"}]

Sends the list of stdin and files in the state.

Outputs:

{"success":{"expr":"writeFile \"/foo\" \"hello\"","stdout":[],"value":"()","files":
{"/hello":"Hello, World!","/functions":"You can also check out removeFile, 
writeFile, appendFile","/files":"Your file system changes will stick around 
in your browser's local storage!","/welcome":"Welcome to your mini 
filesystem! Try playing with this function: getDirectoryContents","/foo":
"hello"},"type":"IO ()"}}

Filesystem state is updated. Likewise I can make it send/receive declarations which will be updated whenever a syntactically valid declaration is typed e.g.

x = 1           let x = 1 in <next>
let x = 1       let x = 1 in <next>

etc.

@sinelaw
Copy link

sinelaw commented Jun 11, 2015

Related, the filterPrime function (in the where) is a partial function because it doesn't pattern match on empty lists. Users who play around with this code and add a limit to the infinite list parameter (e.g. try to set it to [2..1000] will get:

*** Exception: <interactive>:23:5-71: Non-exhaustive patterns in function filterPrime

Another not-nice first impression of Haskell...

BTW, I love the new site!

@ocramz
Copy link

ocramz commented Jan 20, 2017

I agree, the first reaction a new user has with the sieve example is to paste it in the Try It box, and seeing it doesn't work gives a bad impression.

I don't agree with generating unbounded output such as in let pgen (p:xs) = p : pgen [x|x <- xs, mod x p > 0] in pgen [2..], because tryhaskell terminates execution artificially, whereas GHCi won't.

All in all, from a usability PoV, all the homepage examples should work out of the box in tryhaskell.
A simple modification like let pgen (p:xs) = take 10 $ p : pgen [x|x <- xs, x mod p > 0] in pgen [2..] could do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants