[Haskell-cafe] indentation with let and do

Roman Cheplyaka roma
Thu Oct 3 19:16:15 UTC 2013


On Thu, Oct 3, 2013 at 9:44 PM, Brandon Allbery <allbery.b at gmail.com> wrote:

> On Thu, Oct 3, 2013 at 2:31 PM, Corentin Dupont <corentin.dupont at gmail.com
> > wrote:
>
>> test :: Bool -> IO ()
>> test foo = do
>>    let bar = case foo of
>>        True ->  "Foo";
>>        False -> "Bar"
>>    return ()
>>
>> while this one does (just adding one space in front of True and False):
>>
>> test :: Bool -> IO ()
>> test foo = do
>>    let bar = case foo of
>>         True ->  "Foo";
>>         False -> "Bar"
>>    return ()
>>
>
> Do you understand how layout works? Informally, something that is more
> indented is a continuation of the previous expression, while something
> equally or less indented is a new expression. In this case, the previous
> expression is `bar = case foo of` and indenting `True` to the same level as
> `bar` means you have ended the expression starting with `bar =`. Adding
> just one extra space indicates that it's still part of `bar =`.
>
> (ghc is actually being somewhat lenient here; strictly speaking, you are
> not indented beyond the `case` so it should have ended the `case`
> expression. ghc allows some sloppiness like this when there absolutely must
> be something else after, but there are limits mostly imposed by layout
> introducers like `let` and `do`.)
>

Brandon,

Indentation of 'case' itself doesn't matter. The layout is introduced by
'of', and then it's the indentation of the lexeme which follows 'of' that
matters. So GHC is correct here.

Roman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131003/9fc824e0/attachment.htm>



More information about the Haskell-Cafe mailing list