Re: Revamping the numeric classes
Brian Boutel <brian@boutel.co.nz> writes:
* most usage of (+), (-), (*) is on numbers which support all of them.
Yes, but the problem is that the way this is implemented is a nuisance and a hindrance to those who wants to apply these operators to different data types. Also, it means functions become less general than they need to be (or that they need to be parametrized by the necessary operators) E.g. way back, I wrote a simple differential equation solver. Now, the same function *could* have been applied to vector functions, except that I'd have to decide on how to implement all the "Num" stuff that really didn't fit well. Ideally, a nice class design would infer, or at least allow me to specify, the mathematical constraints inherent in an algorithm, and let my implementation work with any data satisfying those constraints. Obviously, a good and elegant, yet simple design of type classes is quite hard. I think it can be done, though. -kzm -- If I haven't seen further, it is by standing in the footprints of giants
moved to haskell-cafe Ketil> E.g. way back, I wrote a simple differential equation solver. Ketil> Now, the same function *could* have been applied to vector Ketil> functions, except that I'd have to decide on how to implement Ketil> all the "Num" stuff that really didn't fit well. Ideally, a Ketil> nice class design would infer, or at least allow me to Ketil> specify, the mathematical constraints inherent in an Ketil> algorithm, and let my implementation work with any data Ketil> satisfying those constraints. the problem is that the --majority, I suppose?-- of mathematicians tend to overload operators. They use "*" for matrix-matrix multiplication as well as for matrix-vector multiplication etc. Therefore, a quick solution that implements groups, monoids, Abelian groups, rings, Euclidean rings, fields, etc. will not be sufficient. I don't think that it is acceptable for a language like Haskell to permit the user to overload predefined operators, like "*". A cheap solution could be to define a type MathObject and operators like :*: MathObject -> MathObject -> MathObject Then, the user can implement: a :*: b = case (a,b) of (Matrix x, Matrix y) -> foo (Matrix x, Vector y) -> bar -- Christoph Herrmann E-mail: herrmann@fmi.uni-passau.de WWW: http://brahms.fmi.uni-passau.de/cl/staff/herrmann.html
participants (2)
-
Ch. A. Herrmann -
Ketil Malde