Re: [Haskell-cafe] proposal: point free case expressions

2009-11-05 Thread Reiner Pope
2009/11/5 Sebastiaan Visser sfvis...@cs.uu.nl:
 Hello all,

 Wouldn't it be nice if we could write point free case statements?

 I regularly find myself writing down something like this:

 myFunc = anotherFunc $ \x - case x of
                                Left err - print err
                                Right msg - putStrLn msg

 We could really use a case statement in which we skip the scrutinee and make
 `(case of {})' be syntactic sugar for `(\x - case x of {})'.

 So we could write:

 myFunc = anotherFunc $ case of
                          Left err - print err
                          Right msg - putStrLn msg

 A minor syntactical addition, a big win!

 Cheers,

 --
 Sebastiaan Visser
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


Morten Rhiger implemented Type-safe pattern combinators [1], which
are essentially a library for pattern matching, entirely within
Haskell98. As an example, he implemented anonymous pattern-matching
with this library, which is similar to what you ask for. It would be
certainly be possible to implement your proposal with his library.

My library first-class-patterns [2] on Hackage essentially follows
Morten Rhiger's approach, but makes the types more understandable. I
implemented point free case expressions (the 'elim' function) and
monadic pattern matches (the 'mmatch' function) in version 0.2.0,
which I just uploaded. For instance, you could write

 import Data.Pattern

  anonymous matching
 ex6 :: Show a = Either a String - IO ()
 ex6 = elim $
 left  var - print
 | right var - putStrLn

 -- monadic matching
 ex8 :: IO ()
 ex8 = mmatch getLine $
 cst  - return ()
 | var- putStrLn . (You said  ++)

Cheers,
Reiner

[1] http://www.itu.dk/people/mir/typesafepatterns.pdf
[2] http://hackage.haskell.org/package/first-class-patterns
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] proposal: point free case expressions

2009-11-05 Thread Nicolas Pouillard
Excerpts from Martijn van Steenbergen's message of Thu Nov 05 16:54:36 +0100 
2009:
 Sebastiaan Visser wrote:
myFunc = anotherFunc $ case of
 Left err - print err
 Right msg - putStrLn msg
  
  A minor syntactical addition, a big win!
 
 +1!

+1

-- 
Nicolas Pouillard
http://nicolaspouillard.fr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] proposal: point free case expressions

2009-11-05 Thread Donn Cave
 +1

If we're counting increments, should add in previous instances of the
same proposal - Andrew Pimlott Sep 2005 on haskell-cafe, at least.

I agree with Stefan Monnier, might as well allow pattern alternatives
in lambda expressions - essentially the same idea and allows multiple
case parameters.

Donn Cave, d...@avvanta.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe