Last active
July 11, 2024 10:18
-
-
Save memowe/cbc92aecfc2347389e6d6441e7396649 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
-- On the "on" operator of Data.Function | |
-- https://hackage.haskell.org/package/base/docs/Data-Function.html#v:on | |
-- | |
-- on :: (b -> b -> c) -> (a -> b) -> a -> a -> c | |
-- with | |
-- (op `on` f) x y = f x `op` f y | |
-- | |
-- Question: is there any way to create a vararg combinator? | |
-- https://wiki.haskell.org/Varargs | |
-- onN :: (b -> b -> ... -> c) -> (a -> b) -> a -> a -> ... -> c | |
on1 :: (b -> c) -> (a -> b) -> a -> c | |
on1 f g = (. g) f | |
on2 :: (b -> b -> c) -> (a -> b) -> a -> a -> c | |
on2 f g = (. g) . on1 f g | |
on3 :: (b -> b -> b -> c) -> (a -> b) -> a -> a -> a -> c | |
on3 f g = ((. g) .) . on2 f g | |
on4 :: (b->b->b->b->c) -> (a -> b) -> a->a->a->a->c | |
on4 f g = (((. g) .) .) . on3 f g | |
-- = (((. g) .) .) . ((. g) .) . on2 f g | |
-- = (((. g) .) .) . ((. g) .) . (. g) . on1 f g | |
-- = (((. g) .) .) . ((. g) .) . (. g) . (. g) f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
meooow on #haskell @ FP discord: