In hoc signo vinces (Was: Revamping the numeric classes)

Marcin 'Qrczak' Kowalczyk
Mon, 12 Feb 2001 13:34:55 +0100 (CET)

On Mon, 12 Feb 2001, Jerzy Karczmarczuk wrote:

> I want to be *able* to define mathematical operations upon objects
> which by their intrinsic nature permit so!

You can't do it in Haskell as it stands now, no matter what the Prelude
would be.

For example I would say that with the definition
    abs x =3D if x >=3D 0 then x else -x
it's obvious how to obtain abs :: ([Int]->Int) -> ([Int]->Int): apply the
definition pointwise.

But it will never work in Haskell, unless we changed the type rules for if
and the tyoe of the result of (>=3D).

You are asking for letting
    abs x =3D max x (-x)
work on functions. OK, in this particular case it can be made to work by
making appropriate instances, but it's because this is a special case
where all intermediate types are appropriately polymorphic.

This technique cannot work in general, as the previous example shows. So
IMHO it's better to not try to pretend that functions can be implicitly
lifted. Better provide as convenient as possible way of manual lifting
arbitrary functions, so it doesn't matter if they have fixed Integer in
the result or not.

You are asking for an impossible thing.

> I defined hundred times some special functions to add lists or
> records, to multiply a tree by a scalar (btw.: J=F3n Fairbarn proposes
> (.*), I have in principle nothing against, but these operators is used
> elsewhere, in other languages, CAML and Matlab; I use (*>) ).

Please show a concrete proposal how Prelude classes could be improved.

Marcin 'Qrczak' Kowalczyk