
Got it. No doubt some of this figures into why I was beaten bloody by ghci last night. Is there a number "tree" somewhere that shows the heirarchy?
Michael
--- On Mon, 10/26/09, Daniel Fischer
Being new to Haskell, I take it (^) and (^^) would be the preferred exponential "operator." When (how,where,why) would one use (**)?
The beasts have different types and are for different things: Prelude> :i (^) (^) :: (Num a, Integral b) => a -> b -> a -- Defined in GHC.Real infixr 8 ^ This one raises any number to a nonnegative integral power. A typical implementation would be power by repeated squaring. Prelude> :i (^^) (^^) :: (Fractional a, Integral b) => a -> b -> a -- Defined in GHC.Real infixr 8 ^^ This one allows also negative powers, so the type of base must allow inversion, hence it must belong to Fractional. The exponent must still be an integer, you can't use this for n-th roots or similar. A typical implementation would be power by repeated squaring, followed by (1/) if the exponent is negative. Prelude> :i (**) class (Fractional a) => Floating a where ... (**) :: a -> a -> a ... -- Defined in GHC.Float infixr 8 ** This one raises a floating point number to an arbitrary power, so you can use it for n-th roots. A typical implementation would be b ** e = exp (e*log b).