#3583: Default view patterns
-----------------------------------------+----------------------------------
  Reporter:  ksf                         |          Owner:                  
      Type:  feature request             |         Status:  new             
  Priority:  normal                      |      Milestone:  _|_             
 Component:  Compiler                    |        Version:  6.10.4          
Resolution:                              |       Keywords:                  
Difficulty:  Moderate (less than a day)  |             Os:  Unknown/Multiple
  Testcase:                              |   Architecture:  Unknown/Multiple
   Failure:  None/Unknown                |  
-----------------------------------------+----------------------------------
Comment (by ksf):

 Well, I think that totally implicit view patterns are probably a very good
 idea, because they reduce the syntactic overhead of abstraction (I'm going
 to pretend to be able to override (:) for the sake of argument):

 {{{
 foo (x:xs) = x + length xs

 vs.

 foo (-> (x:xs)) = x + length' xs

 vs.

 foo xs = head' xs + length' (tail' xs)
 }}}


 Consider parsing libraries: Only uu-parsinglib and Parsec (>=3) support
 matching on arbitrary left-disectable sequences, while certainly every
 parsing library could do that. I think the main reason for this is the
 clarity and ease of matching on (:). While # 2 does certainly look more
 idiomatic than # 3, I fear it would still not be enough to foster wide-
 spread adoption of such abstraction. Even now, uu-parsinglib and Parsec3
 come with separate uncons classes. The same argument applies to [Char] vs.
 ByteString vs. Data.Text vs. Seq Char: gazillions of functions could work
 on all of them, and most likely being made to work (with a bit of luck)
 just by adding an -X flag (I'm in the "safe Haskell by throwing
 typeclasses at it"-camp).

 As I can't see any instance where # 1 and # 2 would differ in anything but
 how often the method "view" can be captured, I certainly prefer the # 1
 for its clarity:

 Providing two language options -- e.g. -XViewPatters and -XImplicitViews
 -- might not only help avoiding Wadler's Law and offload the discussion to
 what's common usage after some time, but also provide a graceful update
 path for code that already has "view" in scope: -XViewPatters would only
 capture it with explitit -> Syntax, -XImplicitViews always. In any case,
 if things won't work out, you'll get a type error.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3583#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to