Reputation: 860
I have the following function g
g :: Int -> Int -> Int
g x y = x + y * y
I use g in the following three ways but don't quite understand what they each do.
map (g 10) [1,2,3,4,5] -- 1
map (10 ‘g‘) [1,2,3,4,5] -- 2
map (‘g‘ 10) [1,2,3,4,5] -- 3
Upvotes: 0
Views: 406
Reputation: 860
x `g` y
is defined on haskell.org as
x `g` y = g x y
This results in the following for
-- 1
map (g 10) [1,2,3,4,5] ==
map (\x -> g 10 x) [1,2,3,4,5]
-- 2
map (10 `g`) [1,2,3,4,5] ==
map (\x -> g 10 x) [1,2,3,4,5]
-- 3
map (`g` 10) [1,2,3,4,5] ==
map (\x -> g x 10) [1,2,3,4,5]
I hope this made it a bit more clear.
Upvotes: 1