Common syntax for casing/matching (Re[2]: Call to arms: lambda-case is stuck and needs your help)

2012-07-12 Thread Bulat Ziganshin
Hello wagnerdm,

Thursday, July 5, 2012, 7:22:38 PM, you wrote:

 After 21 months of occasional arguing the lambda-case proposal(s) is

this reminded me old joke about PL/I: camel is the horse created by committee

i propose to return back and summarize all the requirements we have in
this area. and then try to develop global solution matching them all.
my summary of requirements follows:

 Now we have 3 ways to performing casing/matching:

 function definition:  f (Just x) (Just y) | x0 = ...  multi-line, 
 multi-parameter
 case statement: case ... of Just x | x0 - ... multi-line, single-parameter, 
 different syntax
 lambda: \(Just x) (Just y) - ...  single-line, multi-parameter, case-like 
 syntax

 What we probably need is to have common syntax for all 3 cases.



another interesting feature may be ruby-style matching defined by
execution of special function `match` instead of pattern matching:

switch var of
  1+1 - print var==2
  [5..10] - print var in [5..10]
  (20)   - print var20

where (var `match` (1+1)), (var `match` [5..10]), (var `match` (20)) is tested


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com


___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Common syntax for casing/matching (Re[2]: Call to arms: lambda-case is stuck and needs your help)

2012-07-12 Thread Twan van Laarhoven

On 2012-07-12 23:48, Bulat Ziganshin wrote:

another interesting feature may be ruby-style matching defined by
execution of special function `match` instead of pattern matching:

switch var of
   1+1 - print var==2
   [5..10] - print var in [5..10]
   (20)   - print var20

where (var `match` (1+1)), (var `match` [5..10]), (var `match` (20)) is tested


With view patterns you can write

case var of
((== 1+1) - True) - print var==2
((`elem` [5..10]) - True) - print var in [5..10]
(( 20)   - True) - print var20

Or you can just use guards, of course.


Twan

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users