[Haskell-cafe] Parse error
Hans Aberg
haberg at math.su.se
Sun Jan 17 08:51:32 EST 2010
On 17 Jan 2010, at 11:44, Andrew Coppin wrote:
>>> Urg, but that's *ugly*. Is there no way I can reduce the amount of
>>> indentation to something more reasonable?
>>
>> main = do
>> putStrLn "Line 1"
>> putStrLn "Line 2"
>>
>> let xs = do
>> x <- [1..10]
>> y <- [1..10]
>> return (x+y)
>>
>> print xs
>>
>> That better?
>
> It's an improvement. It's still not pretty, but I guess that's as
> good as it's going to get...
>
> Maybe this is an instance of Haskell trying to tell me "if you need
> to write a 20-line do-block in the middle of your function, you're
> doing it wrong".
Haskell starts the new indentation level where the following lexeme is
(Haskell-98 Report, sec. 2.7). So to reduce indentation, one must
start a new line (already mentioned in this thread). This works in Hugs:
main =
do
putStrLn "Line 1"
putStrLn "Line 2"
let
xs =
do
x <- [1..10]
y <- [1..10]
return (x+y)
print xs
The "xs" on a new line looks a bit unusual, and it takes a bit more
vertical space, but one gets nice indentation levels.
Hans
More information about the Haskell-Cafe
mailing list