[Haskell-beginners] Re: Top beginner mistakes

7stud bbxx789_05ss at yahoo.com
Sun Mar 8 21:55:09 EDT 2009


Benjamin L. Russell <DekuDekuplex <at> Yahoo.com> 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:

--------
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.







More information about the Beginners mailing list