[GHC] #10807: PatternGuards and MultiWayIf layout rules

GHC ghc-devs at haskell.org
Fri Aug 28 22:24:45 UTC 2015


#10807: PatternGuards and MultiWayIf layout rules
-------------------------------------+-------------------------------------
        Reporter:  htebalaka         |                   Owner:
            Type:  bug               |                  Status:  new
        Priority:  lowest            |               Milestone:
       Component:  Compiler          |                 Version:  7.10.2
  (Parser)                           |
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  Documentation     |  Unknown/Multiple
  bug                                |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:  #7783             |  Differential Revisions:
-------------------------------------+-------------------------------------
Changes (by thomie):

 * type:  task => bug
 * related:   => #7783


Old description:

> The layout rules for MultiWayIf currently require any lines starting with
> a comma to be further indented than the lines starting with a pipe when
> used in conjunction with PatternGuards. This is inconsistent with the
> examples given in
> [https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/syntax-
> extns.html#pattern-guards]. For instance, we can't use the same
> indentation in the second example as in the first without triggering a
> parser error.
>
> {{{#!hs
> {-# LANGUAGE PatternGuards, MultiWayIf
>
> fine a pred
>     | Just x <- a
>     , pred x = True
>     | otherwise = False
>
> notFine a pred =
>     if | Just x <- a
>         , pred x -> True
>        | otherwise -> False
> }}}
>
> Though the documentation isn't ''incorrect'', if this intentional it
> could be pointed out, since it's counterintuitive. Otherwise, if there's
> no reason for MulitWayIf to require further indentation that should be
> fixed.

New description:

 The layout rules for MultiWayIf currently require any lines starting with
 a comma to be further indented than the lines starting with a pipe when
 used in conjunction with PatternGuards. This is inconsistent with the
 examples given in
 [https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/syntax-
 extns.html#pattern-guards]. For instance, we can't use the same
 indentation in the second example as in the first without triggering a
 parser error.

 {{{#!haskell
 {-# LANGUAGE PatternGuards, MultiWayIf #}

 fine a pred
     | Just x <- a
     , pred x = True
     | otherwise = False

 notFine a pred =
     if | Just x <- a
         , pred x -> True
        | otherwise -> False
 }}}

 Though the documentation isn't ''incorrect'', if this intentional it could
 be pointed out, since it's counterintuitive. Otherwise, if there's no
 reason for MulitWayIf to require further indentation that should be fixed.

--

Comment:

 Looks like a parser bug to me.

 The following comment in `Parser.y` (introduced in #7783) seems to hint at
 the problem:
 {{{
 -- layout for MultiWayIf doesn't begin with an open brace, because it's
 hard to
 -- generate the open brace in addition to the vertical bar in the lexer,
 and
 -- we don't need it.
 }}}

 With braces the example compiles fine:
 {{{#!haskell
 fineAgain a pred =
     if { | Just x <- a
          , pred x -> True
          | otherwise -> False
        }
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10807#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list