
Here are my top three: 1) Putting an equals sign after a function name when using guards: myfunction x y = | x < 2 = "a" | y > 20 = "b" | otherwise = "c" dhask.hs:2:4: parse error on input `|' Failed, modules loaded: none. 2) Writing "if" in front of the guard conditions: myfunction x y = | if x < 2 = "a" | if y > 20 = "b" | otherwise = "c" dhask.hs:2:25: parse error on input `=' Failed, modules loaded: none. 3) Not putting parentheses around arguments of the form x:xs dosomething x:xs = head xs dhask.hs:1:0: Parse error in pattern Failed, modules loaded: none. In all three cases, the error messages don't help spot the problem.

Those are excellent examples!
I have just added them to HaskellWiki on the following page, and
credited them to you:
Common Misunderstandings - HaskellWiki
http://www.haskell.org/haskellwiki/Common_Misunderstandings
Good work!
-- Benjamin L. Russell
On Wed, 4 Mar 2009 21:54:05 +0000 (UTC), 7stud
Here are my top three:
1) Putting an equals sign after a function name when using guards:
myfunction x y = | x < 2 = "a" | y > 20 = "b" | otherwise = "c"
dhask.hs:2:4: parse error on input `|' Failed, modules loaded: none.
2) Writing "if" in front of the guard conditions:
myfunction x y = | if x < 2 = "a" | if y > 20 = "b" | otherwise = "c"
dhask.hs:2:25: parse error on input `=' Failed, modules loaded: none.
3) Not putting parentheses around arguments of the form x:xs
dosomething x:xs = head xs
dhask.hs:1:0: Parse error in pattern Failed, modules loaded: none.
In all three cases, the error messages don't help spot the problem. -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^

Benjamin L. Russell
Those are excellent examples!
I have just added them to HaskellWiki on the following page, and credited them to you:
Common Misunderstandings - HaskellWiki http://www.haskell.org/haskellwiki/Common_Misunderstandings
Good work!
Thanks! I made a copy and paste error though. The second example still has the equals sign: myfunction x y = which would produce the same error message as the first example. The equals sign should be stricken from the second example. Also, no quotes around 7stud in the attribution! lol.

On Thu, 5 Mar 2009 12:19:55 +0000 (UTC), 7stud
Benjamin L. Russell
writes: Those are excellent examples!
I have just added them to HaskellWiki on the following page, and credited them to you:
Common Misunderstandings - HaskellWiki http://www.haskell.org/haskellwiki/Common_Misunderstandings
Good work!
Thanks! I made a copy and paste error though. The second example still has the equals sign:
myfunction x y =
which would produce the same error message as the first example. The equals sign should be stricken from the second example.
Stricken.
Also, no quotes around 7stud in the attribution! lol.
Quotes removed. Thanks again! -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^

Benjamin L. Russell
Common Misunderstandings - HaskellWiki http://www.haskell.org/haskellwiki/Common_Misunderstandings
I thought I'd point out something wrong with the first beginner mistake listed on that page: -------- 1.1 Indentation ... ... What some miss is that then and else must be indented deeper than the if statement: if boolean then expr1 else expr2 ---------- My tests show that the 'then' and 'else' do not have to be indented more than the 'if': --bhask.hs myfunc x = if x == 2 then "hello" else "goodbye" Prelude> :load bhask.hs [1 of 1] Compiling Main ( bhask.hs, interpreted ) Ok, modules loaded: Main. *Main> myfunc 2 "hello" *Main> myfunc 3 "goodbye" In fact, 'then' and 'else' work for me when they are indented less than the 'if': --bhask.hs myfunc x = if x == 2 then "hello" else "goodbye" *Main> :load bhask.hs [1 of 1] Compiling Main ( bhask.hs, interpreted ) Ok, modules loaded: Main. *Main> myfunc 4 "goodbye" *Main> myfunc 5 "goodbye" *Main> myfunc 2 "hello" I don't if haskell changed its indenting rules or what, but that tip seems to be erroneous.

On 2009 Mar 8, at 21:55, 7stud wrote:
Benjamin L. Russell
writes: Common Misunderstandings - HaskellWiki http://www.haskell.org/haskellwiki/Common_Misunderstandings
I thought I'd point out something wrong with the first beginner mistake listed on that page:
My tests show that the 'then' and 'else' do not have to be indented more than the 'if':
They do, but only within layout, i.e. a "let" or "do", because otherwise they fall outside the layout block. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

2009/3/4 7stud
Here are my top three:
...
3) Not putting parentheses around arguments of the form x:xs
dosomething x:xs = head xs
I have a variation here: function [] = ... function [x:xs] = ... Another of mine is the classical: print function arguments -- or variations but I finally learned to use '$' here .
In all three cases, the error messages don't help spot the problem.
I think that part of the problem is that haskell syntax is powerful but
terse, and therefore is not easy for a compiler to guess the intensions in the programmers. For instance, in any other language the expression 'map f' would give the error "missing second parameter", while in haskell could be a partial function application. However, some of ghc messages could probably be made more 'beginners-friendly'. Ciao --------- FB

Am Donnerstag, 5. März 2009 19:13 schrieb Francesco Bochicchio:
2009/3/4 7stud
Here are my top three:
...
3) Not putting parentheses around arguments of the form x:xs
dosomething x:xs = head xs
I have a variation here:
function [] = ... function [x:xs] = ...
Another of mine is the classical:
print function arguments -- or variations
but I finally learned to use '$' here .
In all three cases, the error messages don't help spot the problem.
At least they give a source position, so you know where to look. But yes, "parse error" is not very specific.
I think that part of the problem is that haskell syntax is powerful but
terse, and therefore is not easy for a compiler to guess the intentions in the programmers. For instance, in any other language the expression 'map f' would give the error "missing second parameter", while in haskell could be a partial function application.
However, some of ghc messages could probably be made more 'beginners-friendly'.
Create a ticket if you encounter a particularly unhelpful error message. If you can suggest a better message, all the better.
Ciao --------- FB
Cheers, Daniel
participants (5)
-
7stud
-
Benjamin L.Russell
-
Brandon S. Allbery KF8NH
-
Daniel Fischer
-
Francesco Bochicchio