So from what I've read about combinators I can't quite tell how they're different from simply chaining function calls. I know I must be missing something but I'm not figuring out what I'm missing. I mean would g(f(x)) (where f and g are functions) effectively be a combinator if I gave it a different name?

  • 3
    Very helpful explanation of combinators: stackoverflow.com/a/7534575/894284 – user39685 May 9 '13 at 16:34
  • @MattFenwick as always, McCann knows this stuff way better than me, and can explain it more clearly as well. – Jimmy Hoffa May 9 '13 at 16:39
  • I thought about checking over on StackOverflow but this seemed more a "Programmers" type of question. Guess I should have trusted my instinct. – Onorio Catenacci May 9 '13 at 17:35
  • @OnorioCatenacci This really is a better fit here; we just have a smaller community so there's less of these questions here and as such less McCann visits here less frequently, and I don't know that I've ever seen Kmett or Don Stewart answer anything here, though they all answer tons over there. You will get better results asking these questions on SO even though they're a better fit for P.SE's scope. – Jimmy Hoffa May 9 '13 at 18:36

Function chaining is known as function composition in the functional world.

A combinator however is a completely different thing, the composition operator is simply one combinator.

I wrote a blog attempting to explain combinators here it may help.

In it I try to explain a combinator is simply a function that follows a few rules in the general case, but in the common case "combinator" is used to refer to a function which abstracts a bit of common functionality that is very basic in form.

in SKI combinator calculus there are 3 combinators: Kxy = x Sxyz = xz(yz) Ix = x

These are combinators because they act only upon their terms, and they are generalized to not care what their terms are.

This seems useless but realize I can be defined in terms of S and K: SKKx = Kx(Kx) = x which is equivalent to Ix which = x, the benefit to combinators is they are fully generalized to whatever terms you pass them and therefore live at a higher level abstraction than other things.

The composition combinator is the B combinator from the B,C,K,W combinator system

Now to make combinators useful however, you have to understand when fully generalized functions like this are worth creating. Parsers are the perfect and most common example, because a parser as a concept has to deal with an extremely large number of possible inputs, therefore the ability to generalize the handling of their inputs comes in very handy.

  • Thanks Jimmy--will read this over when I have a bit more free time – Onorio Catenacci May 9 '13 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.