I’ve been reading about combinators and seen how useful they are (for example, in Haskell’s Parsec). My problem is that I’m not quite sure how to use them practically.
Here’s an outline of the problem: distributions can be generated, filtered, and modified. Distributions may be combined to create new distributions.
The basic interfaces are (in pseudo-Haskell type terminology):
generator:: parameters -> distribution
selector:: parameters -> (distribution -> distribution)
modifier:: parameters -> (distribution -> distribution)
Now, I think that I see three combinators:
combine:: generator -> generator -> generator
filter:: generator -> selector -> generator
modify:: generator -> modifier -> generator
Are these actually combinators? Do the combinators make sense/are there any other obvious combinators that I’m missing?
Thanks for any advice.
The
selectorandmodifierfunctions are already perfectly good combinators! Along withgeneratorandcombineyou can do stuff like (I’m going to assume statistical distributions for concreteness and just make things up!):You may have to mess around a bit with the priority of the combine operator for this to work smoothly 🙂
In general, when I’m trying to design a combinator library for values of type
A, I like to keep myA‘s “at the end”, so that the partially applied combinators (yourselectorandmodifier) can be chained together with.instead of having toflipthrough hoops.Here’s a nice blog article which can help you design combinators, it influenced a lot of my thinking: Semantic Editor Combinators.
EDIT: I may have misread your question, given the type signature of
combine. Maybe I’m missing something, but wouldn’t the distributions be the more natural objects your combinator should work on?