
Hi, This is valid code: module Main where main = do let a = 3 return () Why isn't this one? module Main where main = do { let a = 3; return (); }; Thanks for your help, Maurício

Maurício wrote:
Hi,
This is valid code:
module Main where main = do let a = 3 return ()
That desugars to main = do let a=3 in do return ()
Why isn't this one?
module Main where main = do { let a = 3; return (); };
main = do { let a = 3 in return (); }
Thanks for your help, Maurício
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Maurício wrote:
Hi,
This is valid code:
module Main where main = do let a = 3 return ()
That desugars to main = do let a = 3 in do return ()
Why isn't this one?
module Main where main = do { let a = 3; return (); };
main = do { let a = 3 in return (); }
Thanks for your help, Maurício
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Maurício
Why isn't this one [valid code]?
module Main where main = do { let a = 3; return (); };
My guess is that the compiler is confused about whether you mean do let a = 3 return () or (your intended): do let a = 3 return () A solution which appears to work with GHCi is: do let {a=3}; return () (Note that you don't need the enclosing {}s (although everybody seem to use them), nor the terminating semicolons (they are for statement separation, not termination - Pascal not C) -- they seem to be harmless, though. -k -- If I haven't seen further, it is by standing in the footprints of giants

The problem is that the semicolon after "let a = 3" is consumed as part of the let-declaration. To make sure that the semicolon is not parsed as part of the let, you need to indent it less than the variable "a". For example: module Main where main = do { let a = 3 ; return (); }; Arthur
Why isn't this one [valid]?
module Main where main = do { let a = 3; return (); };
participants (5)
-
Arthur Baars
-
Chris Kuklewicz
-
Chris Kuklewicz
-
Ketil Malde
-
Maurício