David Menendez wrote:
 * Having (+) work on lists, tuples and all the other monoids would
   make error messages more complicated.

It gets worse than that. Imagine trying to explain to someone why "1 +
sin" is actually "\a -> const 1 a + sin a".
It isn't that hard - it is done routinely in mathematics courses. In fact, that is what 1+sin means in Maple today (and has for 25 years). It is also what it means in MuPAD. AFAIK, that is also what 1+Sin means in Mathematica. That is what polymorphism is all about! [This is really equational-theory polymorphism rather than parametric polymorphism, but that's a minor detail, since Monad polymorphism is _also_ equational-theory polymorphism].

This kind of polymorphism [where you add the 'right number' of arrows on the left] is quite useful. Things like differential operators become quite tiresome to write down if you have to pedantically spell everything out, even though there is only one 'sensible' way to interpret a given expression [1].

In the very same way that fromInteger can project a literal integer into other typeclasses, one can project values into spaces of functions by just "adding arrows on the left" (ie exactly what const does). It is possible to make this quite formal, but you need Natural(s) (as an additive monoid) on the type level, and then be able to be polymorphic over _those_ to do make it all work. It should even be decidable [but that part I have not checked]. Something I should write up one of these days, but in the meantime go read [1]!

Jacquces

[1] Bjorn Lisper and Claes Thomberg have already investigated something very close to this, see
http://www.mrtc.mdh.se/index.php?choice=publications&id=0245
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to