Currently I am trying to learn Haskell with the book 'Learn You a Haskell' and I'm trying to understand the implementations of the flip
function in chapter 5. The problem is that the author states that if g x y = f y x
is valid, then f y x = g x y
must be also true. But how and why does this reversal affects the two function definitions?
I know how currying works and I also know that the ->
operator is right-associative by default so the type declarations are in fact the same. I also understand the functions apart from each other but not how the reversal of g x y = f y x
is in relation with this.
first flip function
flip' :: (a -> b -> c) -> (b -> a -> c)
flip' f = g
where g x y = f y x
second flip function
flip' :: (a -> b -> c) -> b -> a -> c
flip' f y x = f x y
f
being used in the definition ofg
, since it's not an argument ofg
? - chepner