What you want seems to be part of binary and unary functions, for example:
compose :: (c -> d) -> (a -> b -> c) -> (a -> b -> d) compose unary binary ab = unary (binary ab)
And you request a free version (without mentioning variables a and b ). Try and eliminate them one by one. We start with b using the fact that f (gx) = f . g f (gx) = f . g :
compose unary binary a = unary . binary a
a next one. First let the desugar expression:
compose unary binary a = ((.) unary) (binary a)
And again apply the same rule:
compose unary binary = ((.) unary) . binary
This can be written as follows:
compose unary = (.) ((.) unary)
Or even how
compose = (.) . (.)
Here, each (.) "Shares" the argument with a binary function, and you need two of them, because the function is binary. This idiom is very useful when generalizing to any functor: fmap . fmap fmap . fmap (note that fmap equivalent . when the function is considered as a functor). This allows you to disable any functor, for example, you can write:
incrementResultsOfEveryFunctionInTwoDimentionalList :: [[String -> Integer]] -> [[String -> Integer]] incrementResultsOfEveryFunctionInTwoDimentionalList = fmap . fmap . fmap $ (+1)
So your result will be:
(fmap . fmap) nub (++)
Edit:
I think I found the answer that my brain was trying to reproduce: The composition operator of a Haskell function like (c → d) → (a → b → c) → (a → b → d)
Rotorsor
source share