Search code examples
haskellfunctional-programmingcomposition

Haskell (.) for function with multiple operands


The (.) operator has the signature:

(.) :: (b -> c) -> (a -> b) -> a -> c
(.) f g x = f $ g x

This looks a bit similar to the composition function in primitive recursive functions with one g.

I'm not interested in extending the number of g-functions, but (a number of) functions that apply the (.) function on a function g with multiple operands. In other words something like:

(..) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
(..) f g x y = f $ g x y

A search on Hoogle doesn't result in any function. Is there a package that can handle this with an arbitrary number of operands?


Solution

  • To answer-ify my comments:

    Multi-argument function composition operators are very easy to define, and luckily someone has done this for you already. The composition package has a nice set of operators for you to use to compose functions in this manner. I also find that instead of using haskell.org's hoogle engine, fpcomplete's version searches through more packages making it easier to find what I'm looking for.