[Haskell-cafe] noob question about powers

Henning Thielemann lemming at henning-thielemann.de
Tue Feb 26 02:39:01 EST 2008


On Tue, 26 Feb 2008, Daniel Fischer wrote:

> Am Dienstag, 26. Februar 2008 01:32 schrieb Ben:
> >
> > Ok, that makes sense.  There's no num k that's both Fractional and
> > Integral, where as in the case where I had the number literals, those
> > were two different instances. What's the usual way of working around
> > this?  Something like
> >
> > (\k -> (1/ fromInteger k) ^ k) 3
> >
> > ?
> Or use another exponentiation operator, in this case (**),

If the exponent is integral it's best to tell the compiler about it, thus
prefer (^)!
 x^3 never raises problems, whereas (-1)**3 may fail, say if the 3 is
actually 3.000000001 due to rounding errors.


More information about the Haskell-Cafe mailing list