Ordinary function composition is of the type
(.) :: (b -> c) -> (a -> b) -> a -> c
I figure this should generalize to types like:
(.) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
A concrete example: calculating difference-squared. We could write diffsq a b = (a - b) ^ 2
, but it feels like I should be able to compose the (-)
and (^2)
to write something like diffsq = (^2) . (-)
.
I can't, of course. One thing I can do is use a tuple instead of two arguments to (-)
, by transforming it with uncurry
, but this isn't the same.
Is it possible to do what I want? If not, what am I misunderstanding that makes me think it should be possible?
Note: This has effectively already been asked here, but the answer (that I suspect must exist) was not given.