http://www.haskell.org/onlinereport/basic.html
6.3 Standard Haskell Classes
-Ross
On Oct 26, 2009, at 3:13 PM, michael rice wrote:
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 <[email protected]> wrote:
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-cafe] Fortran mixed mode arithmetic
expressions -> Haskell
To: "michael rice" <[email protected]>, [email protected]
Date: Monday, October 26, 2009, 1:09 PM
Am Monday 26 October 2009 17:24:46 schrieben Sie:
> 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).
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe