Skip to content

Extend the effects of both BlockArguments and LambdaCase to arrow notation

Alexis King requested to merge lexi.lambda/ghc:arrow-syntax-minor-fixes into master

This MR bundles two distinct (minor) improvements to arrow notation:

  1. When BlockArguments is enabled, its effects now additionally apply to arrow control operators in (| banana brackets |) (fixing #18050 (closed)):

    cmdLam :: () -> ()
    cmdLam = proc () -> (| id \() -> () >- returnA |) ()

    This change is extremely simple, affecting only the parser.

  2. When LambdaCase is enabled, \case is now valid syntax for an arrow command, combining the behavior of lambda commands and case commands the way one would expect.

    foo :: ArrowChoice p => p (Maybe Int) String
    foo = proc x ->
      (| id (\case
         Just x | x > 100   -> returnA -< "big " ++ show x
                | otherwise -> returnA -< "small " ++ show x
         Nothing            -> returnA -< "none")
      |) x

    This change is slightly more involved, since it requires extending the grammar of HsCmd to include a new HsCmdLamCase, the command analogue to HsLamCase. However, the required changes are still quite minimal, and they mostly just amount to moving some code around so it can be shared by both HsCmdCase and HsCmdLamCase.

Both of these are user-facing changes, but they are 100% backwards-compatible, since they don’t change the behavior of any currently-accepted program. Both of them are natural interactions with existing language extensions that were likely just oversights in the first place, seeing as arrow notation doesn’t get much love these days.

Merge request reports