At the time I pointed out that this could be done using
abstract patterns, quite easily. (So why don't we have
abstract patterns yet hint hint.)
The same question came up recently in the Haskell
mailing list, for the same kind of reason.
It occurred to me to try the feature.
SML/NJ has OR-patterns. So consider
fun f ((1,_)|(_,1)) ... ((n,_)|(_,n)) (0,0) = true
| f _ ... _ _ = false
fun g () = f (1,1) ... (n,n) (1,1)
Now the smlnj compiler is normally pretty quick.
And I thought it might be quick on this.
What I really wanted was to measure how long it took
to run, for different values of n.
But I started with n=20, and so far, the compiler
has taken 24 minutes on a 3.2 GHz machine with no
end in sight.
In contrast, using view patterns in Haskell
(the Haskell equivalent of abstract patterns),
ok n (x,_) | x == n = True
ok n (_,x) | x == n = True
ok _ (_,_) = False
f (ok 1 -> True) ... (ok n -> True) (0,0) = True
f _ _ _ = False