[GHC] #8325: Pattern guards in anonymous functions

#8325: Pattern guards in anonymous functions ------------------------------------+------------------------------------- Reporter: mcollis | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- In the course of a project, I had an idea that would allow less cumbersome use of cases in anonymous functions. Here's a simple example of what I'm proposing: {{{ (\x y | x > y -> x | otherwise -> something else) }}} Currently, the only way to accomplish this is with if() then ... else syntax or the use of the MultiWayIf and LambdaCase extensions. The syntax I've proposed here matches with existing anonymous function syntax and doesn't conflict with any other GHC syntax. This would greatly improve the readability of complex anonymous functions. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8325 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8325: Pattern guards in anonymous functions -------------------------------------+------------------------------------- Reporter: mcollis | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): One tricky case would be trying to write something like {{{ f z | odd z = \x y | x > y -> x | otherwise -> y | even z = \x y -> 0 }}} The `| even z` guard has to be attached to `f` because it is followed by `=`, but that requires some look-ahead. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8325#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8325: Pattern guards in anonymous functions -------------------------------------+------------------------------------- Reporter: mcollis | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): `MultiWayIf` uses layout to fix this ambiguity, essentially requiring all the `|` to line up. I find this a bit annoying (but don't have a better idea), because I want to say {{{ if | blah -> blah | blah -> blah }}} which is disallowed. Instead, I need to indent the arrows. In any case, the layout approach should work for lambdas, I think. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8325#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8325: Pattern guards in anonymous functions -------------------------------------+------------------------------------- Reporter: mcollis | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7783, #10807 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * related: => #7783, #10807 Comment: As pointed out in #10807, you can use curly braces: {{{ {-# LANGUAGE MultiWayIf #-} x = if { | True -> 1 | False -> 2 } }}} `MultiWayIf` was changed to use layout in #7783. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8325#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8325: Pattern guards in anonymous functions -------------------------------------+------------------------------------- Reporter: mcollis | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7783, #10807 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): I'm not very familiar with the implementation of `MultiWayIf`, but having `if` introduce layout seems more palatable than having an arbitrary "last variable of lambda" do so... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8325#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8325: Pattern guards in anonymous functions -------------------------------------+------------------------------------- Reporter: mcollis | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7783, #10807 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Wouldn't it be the `|` that introduces the layout? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8325#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC