| > | Another strange thing about n+k patterns.
| > |
| > | Its definition uses >= , but >= is not part of the class Num.
| > | Does that mean that n+k patterns have to be instances of class Real?
| >
| > Certainly. In fact, they're really meant to apply only to class
| > Integral (and it would be natural numbers, if we had them).
|
| Although I'm not surprised about this claim, I think it is a bit against
| the Haskell spirit: for the definition of n+k patterns you need ">=" and
| "-" which determines the class in which they are defined. My remark was
| that in this spirit the use of >= goes farther than necessary.
| Analogy: restrict the use of foldr to homogeneous (type a->a->a) operators?!
Well, successor patterns make most sense if they apply to an algebra
freely generated by zero and successor; that is, the naturals.
| > | One could leave it class Num, if the translation were expressed
| > | in terms of "signum" rather than ">=".
| >
| > Being able to match complex numbers (along the positive real axis only!)
| > with n+k patterns would be a dubious advantage, IMHO.
|
| There is no instance of Ord for complex numbers in the Prelude [unless
| I've missed something], thus they cannot be used (yet) with n+k patterns.
| If you order them pointwise, i.e.
| a:+b <= c:+d = a<=c & b<=d
| then they match the right upper quadrant and not just the real axis.
| In fact you need a rather strange ordering to make them just match the
| real axis.
| IMHO it is not more or less strange to use n+k patterns with
| complex numbers than it is to use them with real or rational numbers.
Maybe I misunderstood what you meant by "in terms of 'signum' rather
than '>='". The only definitions I can think of are something like
case e0 of
x+k -> e1
_ -> e2
translates to
let x' = e0 - k
e1' = e1[x'/x] in
case signum x' of
-1 -> e2
0 -> e1'
1 -> e1'
which diverges when e0 is off the real axis, and
let x' = e0 - k
e1' = e1[x'/x] in
case signum x' of
0 -> e1'
1 -> e1'
_ -> e2
which does not diverge, but matches only values on the real axis.
| > | Question:
| > | Can one misuse the feature of n+k-patterns to simulate
| > | n*k+k' patterns? [I am talking about weird user-defined
| > | instances of Num.]
| >
| > quite possibly.
|
| If we instantiate Num/Ord by setting "negate" to the identity function,
| + to integer division and >= to the divisibility predicate, then
| an n+k pattern actually means n*k.
|
| Looks as if the n+k-pattern gave us the old "views" back,
| although only in a very restricted form.
Indeed, (to join those expressing an opinion on the fate of n+k)
n+k patterns should either be eliminated or subsumed by a general
(and consistent!) views facility.
| --
| Stefan Kahrs
Cheers,
--Joe