Changes between Version 16 and Version 17 of ViewPatterns


Ignore:
Timestamp:
Jan 25, 2007 10:57:53 AM (7 years ago)
Author:
guest
Comment:

added nesting feature

Legend:

Unmodified
Added
Removed
Modified
  • ViewPatterns

    v16 v17  
    366366 
    367367=== Transparent ordinary Patterns === 
     368 
    368369The lightweight view proposal has different syntax for view functions and ordinary pattern matches, they are not interchangeable. To use the abstraction view functions offer, you have to anticipate whether you can stick to ordinary constructors or whether you will switch to abstract constructors at some time. For example, a stack abstraction would have to use view patterns if we want to be able to change the concrete representation of stacks later on. 
    369370{{{ 
     
    379380 
    380381The problem that needs to be solved is to introduce abstraction "after the fact". 
     382 
     383=== Nesting === 
     384 
     385In the lightweight proposal, view patterns are just an extra syntactic form of pattern, and they nest inside other patterns, and other patterns nest inside them.  So one can write 
     386{{{ 
     387  f (sing -> x, True) = ... 
     388  g (Just (sing -> x)) = ... 
     389  h (Just (sing -> Just x)) = ... 
     390}}} 
     391And by the same token, view patterns nest inside each other: 
     392{{{ 
     393  k :: [[a]] -> a 
     394  k (sing -> sing -> x) = x 
     395}}} 
     396This convenient nesting is perhaps the biggest practical  
     397difference between view patterns and pattern guards. 
     398 
     399The majority of the proposals allow nesting. 
    381400 
    382401---------------------------