Chris Smith writes:
... So the current (Num thing) is basically:
1. The type thing is a ring
2. ... with signs and absolute values
3. ... along with a natural homomorphism from Z into thing
4. ... and with Eq and Show.
If one wanted to be perfectly formally correct, then each of 2-4 could be
split out of Num. For example, 2 doesn't make sense for polynomials or n
by n square matrices. 4 doesn't make sense for functions. 3 doesn't
make sense for square matrices of dimension greater than 1. And, this
quirk about 2(x+y) can be seen as an argument for not wanting it in the
case of functions, either. I'm not sure I find the argument terribly
compelling, but it is there anyway.
Why "formally correct"??
This is *your* vision. I might say that fromInteger makes sense for square
matrices, mapping to a multiple of the unity matrix. 4 makes sense for
functions on finite domains. The full Ring property requires a unit, which
might not be there "formally". The "absolute value" might be a buzzword
for <<norm>> which *can* be defined for polynomials. In short, Num is
a conventional hybrid, and trying to squeeze it into *any* math formal
structure is asking for trouble.
On the other hand, I have enough time already trying to explain Num,
Fractional, Floating, RealFrac, ... to new haskell programmes.
... At least in the U.S., very
few computer science students take an algebra course before getting
undergraduate degrees.
Not only in US.
In mathematical terms, the set of functions is a (math) module
("generalized vectorspace"), not a ring.
Well, I agree that functions are modules; but it's hard to agree that
they are not rings. After all, it's not too difficult to verify the ring
axioms.
Oh.
What is the function multiplication?
You say: (f*g)(x) = f x * g x ??
I agree. But if you say that the multiplication IS the *composition*
(for example for the popular implementation of Peano/Church numerals),
then I will also agree. So, there isn't any obvious instance for the
function multiplication. (The composition works even if neither "x" nor
"f x" belong to any ring).
BTW functions "are" or are not members of modules/vector spaces depending
on the codomain structure, so this requires a constrained instance
specification.
Fractional, Floating, etc. are also horrible. Why the square root needs to
be floating? It can belong to the algebraic number domain.
We can continue this ad infinitum. I cared very much about this stuff some
10 years ago, I gave up... I would like, sure, to have the possibility to
derive in Haskell some mathematical subsumptions, e.g., that the ring of
integers modulo N becomes a field if N is prime. Or, that every additive
group is a module over integers. But it seems that we are very far from
such a dream.
Jerzy Karczmarczuk
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe