PROPOSAL: Restrict the type of (^), (^^), and add genericPower,
lemming at henning-thielemann.de
Sat Nov 17 10:09:20 EST 2007
On Sat, 17 Nov 2007, Ian Lynagh wrote:
> Hi all,
> This got a warm reception when I mentioned it in
> so I'm formally proposing it now. It's trac #1902:
> Note that this is a divergence from Haskell 98 (but the libraries
> already have a handful of small divergences, and Haskell' is just around
> the corner...).
> In my opinion, (^) has the wrong type. Just as we have, for example,
> (!!) :: [a] -> Int -> a
> genericIndex :: (Integral b) => [a] -> b -> a
> we should also have
> (^) :: (Num a) => a -> Int -> a
> genericPower :: (Num a, Integral b) => a -> b -> a
> (or some other function name). The same goes for (^^) (genericPower').
I vote for this proposal.
In order not to overuse the prime, I propose genericFractionalPower or
genericFracPower for (^^).
In my code, the exponent is most oftenly 2.
More information about the Libraries