Skip to content

PatternGuards and MultiWayIf layout rules

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.

{-# 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.

Edited by Thomas Miedema
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information