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

Reply via email to