Re: [Haskell-cafe] Bad "let..do" syntax

2007-05-17 Thread Chad Scherrer

Thanks, I had forgotten about multiple let bindings as something it
might be looking for. I guess in this case the curly braces aren't too
bad, given that this situation doesn't come up so much, and it would
let me keep the indentation consistent.

And yes, this is just a boiled-down version of the original code,
where sum [0.. x+1] wasn't an option.

-Chad

On 5/17/07, David House <[EMAIL PROTECTED]> wrote:

On 17/05/07, Chad Scherrer <[EMAIL PROTECTED]> wrote:
> But GHC complains of "Empty 'do' construct".

Because it takes the indented following lines as being new bindings in
the let-block. The trick is to intent them past the 'sum':

let b = sum $ do
  y <- [0..x + 1]
  return y

Or to bypass layout altogether:

let { b = sum $ do
  y <- [0..x + 1]
  return y }

(Of course, in this specific case I'd write sum [0..x + 1], but I
guess that this is an example of a general case.)

--
-David House, [EMAIL PROTECTED]


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Bad "let..do" syntax

2007-05-17 Thread David House

On 17/05/07, Chad Scherrer <[EMAIL PROTECTED]> wrote:

But GHC complains of "Empty 'do' construct".


Because it takes the indented following lines as being new bindings in
the let-block. The trick is to intent them past the 'sum':

let b = sum $ do
 y <- [0..x + 1]
 return y

Or to bypass layout altogether:

let { b = sum $ do
 y <- [0..x + 1]
 return y }

(Of course, in this specific case I'd write sum [0..x + 1], but I
guess that this is an example of a general case.)

--
-David House, [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Bad "let..do" syntax

2007-05-17 Thread Chad Scherrer

I've gotten into a habit of preceding most "do"s in my code with a
"$", and indenting the next line. I kind of like this, since it makes
the indentation more uniform. But it seems to have bitten me now. I'd
like to write something like this

s = sum $ do
 x <- [1,2,3]
 let b = sum $ do
   y <- [0..x + 1]
   return y
 return (x + b)

But GHC complains of "Empty 'do' construct". It likes the alternative

s' = sum $ do
 x <- [1,2,3]
 let b = sum $ do y <- [0..x + 1]
  return y
 return (x + b)

just fine, but that looks horrible to me (ok, "horrible" is a bit
strong, but I don't like it as much).

So I'm wondering, (1) Is this intended to give an error, or is it just
a momentary hiccup, and (2) if others have run into this, is there a
more aesthetic alternative that works?

Thanks,

Chad
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe