It's unclear how to create a useful library using combinators.

I read about combinators and saw how useful they are (e.g. in Haskell Parsec). My problem is that I'm not quite sure how to use them in practice.

This is the outline of the problem: distributions can be generated, filtered, and modified. Distributions can be combined to create new distributions.

The main interfaces (in pseudo-Haskell type terminology):

generator:: parameters -> distribution selector:: parameters -> (distribution -> distribution) modifier:: parameters -> (distribution -> distribution) 

Now I think I see three combinators:

 combine:: generator -> generator -> generator filter:: generator -> selector -> generator modify:: generator -> modifier -> generator 

Are they actually combinators? Combinators make sense / are there any other obvious combinators that I miss?

Thanks for any advice.

+8
functional-programming haskell combinators higher-order-functions
source share
1 answer

The selector and modifier functions are already perfectly combined! Along with generator and combine you can do things like (I'm going to accept statistical distributions for specificity and just do everything!):

 modifier (Scale 3.0) $ generator StandardGaussian `combine` selector (LargerThan 10) . modifier (Shift 7) $ generator (Binomial 30 0.2) 

You may need to work a bit with the priority of the combine operator so that it works smoothly :)

In general, when I try to create a combinator library for values ​​of type A , I like to keep my A β€œat the end”, so that partially used combinators (your selector and modifier ) can be linked together . instead of having flip through hoops.

Here's a good blog article that can help you plan combinators, it has influenced many of my thoughts: Combinators semantic editor .

EDIT: Perhaps I misunderstood your question, given a signature like combine . Maybe I missed something, but wouldn’t the distributions be more natural objects that your combinator should work on?

+5
source share

All Articles