Burning more bridges (mostly numeric ones)

Henning Thielemann schlepptop at henning-thielemann.de
Sun Mar 23 18:25:54 UTC 2014


Am 23.03.2014 09:50, schrieb Bart Massey:

>>> * The multiplicity of exponentiation functions, one of which looks
>>> exactly like C's XOR operator, which I've watched trip up newbies a
>>> bunch of times. (Indeed, NumericPrelude seems to have added more of
>>> these, including the IMHO poorly-named (^-) which has nothing to do
>>> with numeric negation as far as I can tell. See "unary negation"
>>> above.)
>>
>> It is unfortunate, but there really is a distinction being made.
>
> I get that. I even get that static-typing exponentiation is hard. (You
> should see how
> we did it in Nickle (http://nickle.org) --not because it's good but because
> it calls out a lot of the problems.) What I don't get is why the names seem
> so terrible to me, nor why the typechecker can't do more to help reduce the
> number of needed operators, ideally to one. It might mean extra conversion
> operators around exponentiation once in a while, I guess?

I think the power functions of Haskell are the best we can do, and 
mathematics is to blame for having only one notation for different power 
functions.

http://www.haskell.org/haskellwiki/Power_function

I like to compare it to division. In school we first learnt natural 
numbers and that division cannot always be performed with natural 
numbers. Instead we have division with remainder. In contrast to that we 
can always divide rational numbers (except division by zero). In Haskell 
this is nicely captured by two different functions div and (/). The same 
way I find it sensible to distinguish power functions.


I found the infix operator names (^^) and (**) not very intuitive and 
defined (^-) and (^/) in NumericPrelude, in order to show, that the 
first one allows negative exponents and the second one allows fractional 
exponents. Unfortunately the first one looks like power function with 
negated exponent and I had no better idea for an identifier so far.



More information about the Libraries mailing list