Let's say we have this point-free function:
f1 = flip const map
I'm clueless about how exactly does it work and what it is supposed to do? I.e. I know what map, const and flip functions are. But putting them together like this just doesn't make sense to me. What exactly is happening inside this function? It seems to return the same thing I pass into it every time but... Why?
Keep in mind that all functions in Haskell take only one argument but simulate taking multiple arguments by returning another function. So flip const map
can also be written as (flip const) map
. const
normally ignores its second argument and returns its first argument. flip
reverses the order of the arguments, so flip const
ignores the first argument and returns the second argument. So map
gets ignored and a function is returned that always returns its argument.
Let's see what this function does, bit by bit
flip const map x = (flip const) map x
= const x map
= x
That's why it always returns what you give it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With