[Haskell-beginners] Re: let indenting problems

Daniel Fischer daniel.is.fischer at web.de
Mon Mar 2 15:07:27 EST 2009


Am Montag, 2. März 2009 20:42 schrieb 7stud:
>
> mySort xs = let myCompare x y
>
>                 | lx < ly = LT
>                 | lx == ly = EQ
>                 | lx > ly = GT
>
>                    where
>                     lx = length x
>                     ly = length y
>                in sortBy myCompare xs
>
>
>
>
> Prelude> :load bhask.hs
> [1 of 1] Compiling Main             ( bhask.hs, interpreted )
>
> bhask.hs:4:16: parse error (possibly incorrect indentation)
> Failed, modules loaded: none.
> Prelude>
>
>
> Line 4 is the first guard.
>

That line must be indented further than the first letter of myCompare in the 
line above.

After the keyword 'let', the position of the start of the next significant 
token (not whitespace or comments), sets a new indentation level. The 
definiton begun there extends until
- a line indented less or equally far is encountered
- the keyword 'in' appears
- an explicit semicolon ends the definition
If a line indented less appears before the keyword 'in', a parse error 
results. Details can be found in 
http://haskell.org/onlinereport/syntax-iso.html#sect9.3



More information about the Beginners mailing list