Hello good evening. I just want to ask a sample of using flip within a non-numeric data type, since I’m having a hard time creating one. Thanks!
1 Like
Maybe one related to your mapA
, forA
question:
forA = flip mapA
That is actually how forA
is implemented.
flip
just changes the order of the arguments of a two parameter function:
flip : (a -> b -> c) -> (b -> a -> c)
flip fn x y = fn y x
Note that I’ve added parentheses for clarity above. The actual signature is (a -> b -> c) -> b -> a -> c
which is equivalent by associativity. But basically, stick a function with two parameters of types a
and b
in, get a function with two parameters of types b
and a
out.
4 Likes
On a lighter note, your pointer made me notice this code that makes even too much sense:
2 Likes