Hi, I believe one problem with non-linear patterns would be that the compiler has to figure out what notion of equality you want here. An obvious choice is (==), but the Eq instances might not do what you want. Using pattern guards or view patterns explicates this choice.
Also, without an explicit call to == the cost model of such a function definition might be harder to see; an innocent looking change to the patterns of a function could cause a considerable amount of extra work if == is expensive. Greetings, Joachim Am Montag, den 08.04.2013, 07:06 -0700 schrieb Conal Elliott: > Hi Jan, > > 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). > > 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. > > > > -- Conal > > > > > On Mon, Apr 8, 2013 at 6:11 AM, Jan Stolarek <jan.stola...@p.lodz.pl> > wrote: > > You can achieve something similar with the ViewPatterns > language > > extension. > > > > > member _ [] = False > > member x (((x ==) -> True) : _) = True > > member x (_ : xs) = member x xs > > Hi Tillmann, > > there are a couple of ways to achieve this in Haskell, for > example using guards: > > member :: Eq a => a -> [a] -> Bool > member _ [] = False > > member y (x:_) | x == y = True > member y (_:xs) = member y xs > > The goal of my proposal is to provide a concise syntax, > whereas ViewPatterns are very verbose and > guards are slightly verbose. I want something simple and > something that is very intuitive if > you've programmed in Prolog :) > > Janek > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Joachim "nomeata" Breitner Debian Developer nome...@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C JID: nome...@joachim-breitner.de | http://people.debian.org/~nomeata
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe