[Haskell-cafe] Pattern matching with where free variables can be used more than once

Christopher Done chrisdone at googlemail.com
Sun Jul 26 11:54:29 EDT 2009

Well, as I said previously, in reply to Wolfgang, forget the (==) and/or Eq
instance; just use the constructors. You don't need an Eq instance for them.

You have the expression:

foo (a,b)

and the definition:

foo (X,X) = ..

Let's say the predicate for checking that the value of `a' matches X is
Predicate A.

Likewise, for

foo (x,x) = ...

We can use Predicate A to compare `a' and `b', for determining whether the
(x,x) pattern succeeds.

2009/7/18 Richard O'Keefe <ok at cs.otago.ac.nz>

> On Jul 18, 2009, at 6:35 AM, Christopher Done wrote:
> [non-linear patterns]
> This kind of matching is provided in Prolog and Erlang.
> Neither of them lets the user define equality.
> We find the same issue with
>   n+k   patterns               (e.g., n+1 as a pattern)
>   l++r  patterns               (e.g., "prefix"++tail)
>   (x,x) patterns (hidden ==)
> In each case, the question is "what if the Prelude's version
> of the explicit or implied function is not in scope?"  (For
> n+k patterns, is the relevant function "+" or is it ">=" and "-"?
> For l++r patterns, is it "++", or "null", "head", and "tail"?)
> My preferred answer would be to say "the only functions in
> scope in a pattern are constructors; these aren't functions,
> they're syntax, and they always relate to the Prelude."
> The Haskell' community's preferred answer seems to be
> "avoid the question, ban the lot of them."
> It's fair to say that any such pattern _can_ be rewritten to
> something Haskell can handle; it's also fair to say that the
> result is often less readable, but that a rewrite may reduce
> the pain.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090726/513554ee/attachment.html

More information about the Haskell-Cafe mailing list