[GHC] #4359: Implement lambda-case/lambda-if

GHC cvs-ghc at haskell.org
Thu Jul 12 21:29:38 CEST 2012


#4359: Implement lambda-case/lambda-if
-------------------------------+--------------------------------------------
  Reporter:  batterseapower    |          Owner:                  
      Type:  feature request   |         Status:  new             
  Priority:  normal            |      Milestone:  7.6.1           
 Component:  Compiler          |        Version:  7.1             
Resolution:                    |       Keywords:                  
        Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
   Failure:  None/Unknown      |     Difficulty:  Unknown         
  Testcase:                    |      Blockedby:                  
  Blocking:                    |        Related:                  
-------------------------------+--------------------------------------------

Comment(by jeltsch):

 Replying to [comment:69 simonpj]:
 > `\case`, with exactly the same case alternatives as an ordinary `case`
 expression. That is, each alternative has a single un-parenthesised
 pattern. Thus `\case { Just x -> x+1; Nothing -> 0 }`

 Could this extension '''please''' also cover {{{proc case}}} then? Note
 that currently the situation for arrow programming is even worse than for
 “ordinary” programming. If the case distinction happens at the outermost
 point of a definition, then in the case of “ordinary” programming, you
 have the possibility to use pattern matching on the left hand sides of
 equations like so:
 {{{
 f pat1 = rhs1
 f pat2 = rhs2
 ...
 }}}
 But in the case of arrow programming, you don’t have such a possibility,
 so that you have to resort to something like this:
 {{{
 f = proc x -> case x of
         pat1 -> rhs1
         pat2 -> rhs2
         ...
 }}}
 A {{{proc case}}} would be of great help here.

 >   The `\case` becomes a layout herald.  It would be fine if the
 implementation does not permit any space between the backslash and the
 `case`; but if it's easier to allow space there, that's ok too.

 For {{{proc case}}}, the space would be mandatory. So it would make sense
 to also allow space between {{{\}}} and {{{case}}}, that is, treat {{{\}}}
 and {{{case}}} as two different tokens. I don’t know if it’s common to
 treat a group of two tokens as a layout herald. If not, then it might be
 better to use {{{\ of}}} instead of {{{\ case}}}, since the single
 {{{of}}} is already a layout herald.

 > (Personally I'd strongly discourage programmers from using space there.)

 I have the exact opposite opinion. In the case of ordinary lambda
 expressions, it is sometimes necessary to put a space after the {{{\}}},
 namely, if the {{{\}}} is followed by a {{{~}}}. So I think it’s a good
 idea to always insert a space after {{{\}}} to have a consistent style.
 This should probably carry over to {{{\ case}}} then.

 > Multi-branch `if`: `if | x>0 -> -1 | x==0 -> 0 | otherwise -> 1`

 It would be great to also have an arrow version of this. This would have
 arrow commands instead of expressions after the {{{->}}}’s, and would
 itself be an arrow command.

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



More information about the Glasgow-haskell-bugs mailing list