Why
map (^2) [1..10]
and
map (2^) [1..10]
Job?
I expect it to work with only one of them, and not for both.
I thought the map would iterate over all the elements [1..10]and then do
[1..10]
[1^2, 2^2, 3^2, ...]
for map (^2) [1..10]. Then I would expect that when given, map (2^) [1..10]this would lead to a sintax error or something else, because that would require a number after ^, not before.
^
Haskell , " ". - , say #$%, :
#$%
(#$%) = \x y -> x #$% y (#$% y) = \x -> x #$% y (x #$%) = \y -> x #$% y
, , , , Forth, . , , " , ".
( - f + x f , + ? , ? : (), .)
f + x
f
+
()
Haskell , ^ , ( ) (2^) f(x) = 2^x (^2) f(x) = x^2.
(2^)
f(x) = 2^x
(^2)
f(x) = x^2
(2 ^) creates a new function that takes a parameter and calls (parameter 2 ^). This is a curryfication way.
Here's a link to the theory behind it: Partial Application (Haskell.org)