[Haskell-cafe] Re: Pointfree composition for higher arity

oleg at okmij.org oleg at okmij.org
Thu Feb 18 01:54:48 EST 2010

Sean Leather wrote:
> (...) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
> (...) f g x y = f (g x y)

> Does anybody else care about this? What are some alternative
> solutions?

Here is a different solution:


         f:: a1->a2-> .... ->cp  (where cp is not a function type)
         g:: cp->d
         f `mcomp` g:: a1->a2-> .... ->d

Now that we know how to generically decide if a type is not a
functional type, mcomp can be defined fully generically, for any type
cp that is not a function. If there is interest, I can write that

One particular application of the mcomp combinator is the prod combinator:
Given two functions,
   f:: a1->a2->...->an->c   |c,d non-exponential types
   g:: b1->b2->...->bn->d
their product f `prod` g:: a1->a2->...->an->b1->b2->...->bn->(c,d)
The number of as and bs is arbitrary.

The definition of prod is very simple:

> prod = (. ((. (,)) . mcomp)) . mcomp

The web page
gives a few explanations and further examples.

More information about the Haskell-Cafe mailing list