<div dir="ltr"><div>Hi Jan,<br><br>What you're suggesting is called "non-linear patterns", and it's a perfectly sensible, well-defined feature in a language with pattern-matching. As you point out, non-linearity allows for more direct & succinct programming. I've often wished for this feature when writing optimizations on data types, especially for syntactic types (languages).<br>
<br>As Ivan mentioned, there is some danger that people may accidentally a non-linear pattern accidentally, and perhaps the early Haskell designers chose the linearity restriction out of this worry. The importance of such dangers is a subjective call, and certainly not one carried out consistently in Haskell. Consider, for instance, the choice that let & where bindings are recursive by default in Haskell, unlike ML and Lisp. I like this choice, but I can understand objections that it leads to accidental recursions, especially for non-functions.<br>
<br><br></div>-- Conal<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 8, 2013 at 6:11 AM, Jan Stolarek <span dir="ltr"><<a href="mailto:jan.stolarek@p.lodz.pl" target="_blank">jan.stolarek@p.lodz.pl</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">> You can achieve something similar with the ViewPatterns language<br>
> extension.<br>
><br>
</div><div class="im">> member _ [] = False<br>
> member x (((x ==) -> True) : _) = True<br>
> member x (_ : xs) = member x xs<br>
</div>Hi Tillmann,<br>
<br>
there are a couple of ways to achieve this in Haskell, for example using guards:<br>
<div class="im"><br>
member :: Eq a => a -> [a] -> Bool<br>
member _ [] = False<br>
</div>member y (x:_) | x == y = True<br>
member y (_:xs) = member y xs<br>
<br>
The goal of my proposal is to provide a concise syntax, whereas ViewPatterns are very verbose and<br>
guards are slightly verbose. I want something simple and something that is very intuitive if<br>
you've programmed in Prolog :)<br>
<br>
Janek<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>