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

2009-07-26 Thread Christopher Done
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

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

2009-07-23 Thread wren ng thornton
Richard O'Keefe wrote: 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 patte

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

2009-07-17 Thread Richard O'Keefe
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

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

2009-07-17 Thread Wolfgang Jeltsch
Am Freitag, 17. Juli 2009 20:38 schrieb Stefan Holdermans: > Christopher, > > > Wouldn't it be great if pattern variables could be used more than once > > in a pattern? Like so: > > > >foo [x,x,_,x] = "The values are the same!" > >foo _ = "They're not the same!" > > These are called n

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

2009-07-17 Thread Stefan Holdermans
Christopher, Wouldn't it be great if pattern variables could be used more than once in a pattern? Like so: foo [x,x,_,x] = "The values are the same!" foo _ = "They're not the same!" These are called nonlinear patterns. I think Miranda (a precursor of Haskell, sort of) used to ha

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

2009-07-17 Thread Christopher Done
Wouldn't it be great if pattern variables could be used more than once in a pattern? Like so: foo [x,x,_,x] = "The values are the same!" foo _ = "They're not the same!" where this could be rewritten to: foo [x,y,_,z] | x == y && x == z = "The values are the same!" foo _