[Haskell-beginners] Explanation of double astrix
chaddai.fouche at gmail.com
Wed Sep 3 11:12:41 EDT 2008
2008/9/3 Paul Johnston <Paul.A.Johnston at manchester.ac.uk>:
> Was playing around with ghci and lambda expressions and:
> *Main> map (\x -> 2 * x) [1 ..3]
> Then thinking back to Fortran (yes I'm not young anymore!)
> *Main> map (\x -> 2 ** x) [1 ..3]
I don't know what (**) did in Fortran, but in Haskell it's a
exponentiation, which is why it only works on floating point numbers
(Double and Float are two instances of the Floating typeclass).
The definition of (**) in the Prelude :
x ** y = exp (log x * y)
You can quickly find it using Hoogle (I recommend you take the habit
of using this excellent tool).
For integral powers, you can use (^).
More information about the Beginners