
Is there a specific reason why GHC consistently refuses to accept the following perfectly reasonable code snippet? main = do putStrLn "Line 1" putStrLn "Line 2" let xs = do x <- [1..10] y <- [1..10] return (x+y) print xs No matter which way I rearrange this, it *insists* that there's a parse error. This is very frustrating, given that it's utterly clear what I want...

let ... in ... I guess GHC is finding where "in" is. 在 2010年 1月 17日 星期日 18:05:47,Andrew Coppin 寫道:
Is there a specific reason why GHC consistently refuses to accept the following perfectly reasonable code snippet?
main = do putStrLn "Line 1" putStrLn "Line 2"
let xs = do x <- [1..10] y <- [1..10] return (x+y)
print xs
No matter which way I rearrange this, it *insists* that there's a parse error. This is very frustrating, given that it's utterly clear what I want...
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sun, 2010-01-17 at 18:10 +0800, VoidPrayer wrote:
let ... in ...
I guess GHC is finding where "in" is.
Except that: main = do l <- getLine let l' = lines l print l' Is perfectly valid without in. Similary: something = proc (x, y) -> do x' <- someArrow -< x let z = x + y + x' returnA -< z Regards

Oh, I should know that. Thank you. By the way, is it only valid when "let" only affects the one expression after that? I read "where vs let" in the HaskellWiki but all the examples are "let ... in". 在 2010年 1月 17日 星期日 22:13:14,Maciej Piechotka 寫道:
On Sun, 2010-01-17 at 18:10 +0800, VoidPrayer wrote:
let ... in ...
I guess GHC is finding where "in" is.
Except that:
main = do l <- getLine let l' = lines l print l'
Is perfectly valid without in. Similary:
something = proc (x, y) -> do x' <- someArrow -< x let z = x + y + x' returnA -< z
Regards
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello VoidPrayer, Sunday, January 17, 2010, 5:32:55 PM, you wrote:
By the way, is it only valid when "let" only affects the one expression after that? I read "where vs let" in the HaskellWiki but all the examples are "let ... in".
the "let" inside "do" is just a syntax sugar: do xxx let yyy zzz ttt is equivalent to do xxx let yyy in do zzz; ttt -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

No, but there's a specific reason why GHC consistently refuses to accept your perfectly unreasonable code snippet :) GHC accepts the following perfectly reasonable code snippet: main = do putStrLn "Line 1" putStrLn "Line 2" let xs = do x <- [1..10] y <- [1..10] return (x+y) print xs Andrew Coppin wrote:
Is there a specific reason why GHC consistently refuses to accept the following perfectly reasonable code snippet?
main = do putStrLn "Line 1" putStrLn "Line 2"
let xs = do x <- [1..10] y <- [1..10] return (x+y)
print xs
No matter which way I rearrange this, it *insists* that there's a parse error. This is very frustrating, given that it's utterly clear what I want...
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Tony Morris http://tmorris.net/

Tony Morris wrote:
No, but there's a specific reason why GHC consistently refuses to accept your perfectly unreasonable code snippet :)
She sells csh on the sea shore. :-)
GHC accepts the following perfectly reasonable code snippet:
main = do putStrLn "Line 1" putStrLn "Line 2"
let xs = do x <- [1..10] y <- [1..10] return (x+y)
print xs
Urg, but that's *ugly*. Is there no way I can reduce the amount of indentation to something more reasonable?

Am Sonntag 17 Januar 2010 11:33:45 schrieb Andrew Coppin:
Tony Morris wrote:
No, but there's a specific reason why GHC consistently refuses to accept your perfectly unreasonable code snippet :)
She sells csh on the sea shore. :-)
GHC accepts the following perfectly reasonable code snippet:
main = do putStrLn "Line 1" putStrLn "Line 2"
let xs = do x <- [1..10] y <- [1..10] return (x+y)
print xs
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?

Daniel Fischer wrote:
Am Sonntag 17 Januar 2010 11:33:45 schrieb Andrew Coppin:
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".

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

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".
20 lines is a lot, but I have smaller ones all the time. You need >4 spaces of indent to continue a let. Here's another way to understand why: f = do let x = some big expression y = another big expression x y If you wonder why "multiple let" syntax is needed, well I don't really know for sure, but consider if x and y were mutually recursive. I was annoyed at first with all the indentation but got used to it. I use 4 space indents so it works out ok. Binding with <- or in where can reduce the indentation but is not always appropriate.

On Sun, Jan 17, 2010 at 10:33:45AM +0000, Andrew Coppin wrote:
Tony Morris wrote:
main = do putStrLn "Line 1" putStrLn "Line 2"
let xs = do x <- [1..10] y <- [1..10] return (x+y)
print xs
Urg, but that's *ugly*. Is there no way I can reduce the amount of indentation to something more reasonable?
Sure: start a new line and indentation level after every where, let, do or of.

Am Sonntag 17 Januar 2010 11:05:47 schrieb Andrew Coppin:
Is there a specific reason why GHC consistently refuses to accept the following perfectly reasonable code snippet?
Yes, you violated the layout rule.
main = do putStrLn "Line 1" putStrLn "Line 2"
let xs = do x <- [1..10] y <- [1..10] return (x+y)
print xs
No matter which way I rearrange this, it *insists* that there's a parse error. This is very frustrating, given that it's utterly clear what I want...
It's not. ACLayout.hs:7:11: Empty 'do' construct should give a hint (line 7 is " let xs = do"). The next line after that is indented less than the "xs", so it ends the binding for xs (in fact, the entire let binding group) . You have to indent the lines in the do-block defining xs more than xs itself.
participants (9)
-
Andrew Coppin
-
Bulat Ziganshin
-
Daniel Fischer
-
Evan Laforge
-
Hans Aberg
-
Maciej Piechotka
-
Ross Paterson
-
Tony Morris
-
VoidPrayer