Last active
October 17, 2020 15:17
-
-
Save inamiy/2cc0ac5dd91e8051dd754c0b1f48ad5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flipAll2 :: (t1 -> t2 -> t3) -> t2 -> t1 -> t3 | |
flipAll2 = flip | |
-- flip 1st & 2nd arg | |
flipAll3 :: (t1 -> t2 -> t3 -> t4) -> t3 -> t2 -> t1 -> t4 | |
flipAll3 = flipAll2 . (flip .) . flip | |
-- flip 1st & 2nd arg, 2nd & 3rd arg, goto flipAll2 | |
flipAll4 :: (t1 -> t2 -> t3 -> t4 -> t5) -> t4 -> t3 -> t2 -> t1 -> t5 | |
flipAll4 = flipAll3 . ((flip .) .) . (flip .) . flip | |
-- flip 1st & 2nd arg, 2nd & 3rd arg, 3rd & 4th arg, goto flipAll3 | |
flipAll5 :: (t1 -> t2 -> t3 -> t4 -> t5 -> t6) -> t5 -> t4 -> t3 -> t2 -> t1 -> t6 | |
flipAll5 = flipAll4 . (((flip .) .) .) . ((flip .) .) . (flip .) . flip | |
-- well, you know the pattern! | |
-- Tips: Here are some useful n-ary function mappings | |
\f g -> (f .) . g :: (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c | |
\f g -> ((f .) .) . g :: (b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c | |
\f g -> (((f .) .) .) . g :: (b -> c) -> (a1 -> a2 -> a3 -> a4 -> b) -> a1 -> a2 -> a3 -> a4 -> c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment