
3 Sep
2008
3 Sep
'08
3:12 p.m.
2008/9/3 Paul Johnston
Hi Was playing around with ghci and lambda expressions and:
*Main> map (\x -> 2 * x) [1 ..3] [2,4,6]
Then thinking back to Fortran (yes I'm not young anymore!)
*Main> map (\x -> 2 ** x) [1 ..3] [2.0,4.0,8.0]
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 (^). -- Jedaï