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

Chad Scherrer chad.scherrer at gmail.com
Thu May 17 15:17:18 EDT 2007


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 <dmhouse at gmail.com> wrote:
> On 17/05/07, Chad Scherrer <chad.scherrer at gmail.com> 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, dmhouse at gmail.com
>


More information about the Haskell-Cafe mailing list