[Haskell-cafe] How to use "bracket" properly ?

Luke Palmer lrpalmer at gmail.com
Mon Oct 19 08:46:01 EDT 2009


On Mon, Oct 19, 2009 at 6:10 AM, Roel van Dijk <vandijk.roel at gmail.com> wrote:
> On Mon, Oct 19, 2009 at 1:44 PM, zaxis <z_axis at 163.com> wrote:
>> oh! thanks!  But why ?
>
> A let can introduce multiple declarations.
>
> So this
>
> foo = do
>  let x = 3
>  let y = 4
>  return $ x+ y
>
> can also be written like
>
> foo = do
>  let x = 3
>      y = 4 -- no let
>  return $ x + y

To be clear, the reason this breaks is because this is a valid let syntax:

let x = 1 ; y = 2 in x + y

See the semicolon?  So when you put a let in a block, and it sees the
semicolon at the end of the line, it is expecting another let binding.
 If there's a newline, then the layout rule applies and the next line
is considered the start of a new layout block, even though it's at the
same level.

So, basically, everything gets borked up.

> With explicit blocks:
>
> foo = do {
>  let {x = 3; y = 4;};
>  return $ x + y;
> }
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list