Skip to content
Robert Peszek edited this page Sep 14, 2013 · 1 revision

Functions as Monads

The main motivation for implementing ClosureMonad has been the comprehension syntax (MonadicComprehensions).

Effectively, this makes comprehensions into a first example of 'function builders' (which are on Fpiglet long range todo list - Roadmap).

def a = ...
def b = ...
def c = ...
def d = ...
//now create poly(x) = a x^3 + b x^2 + c x + d

Closure poly = selectP { a*x3 + b*x2 + c* x + d }.from {
  x3 << { POWER(_,3) }
  x2 << { POWER(_,2) }
  x  << { POWER(_,1) }
}

This syntax should work well with property-based testing (Gruesome integration).

If you are comparing this to Haskell, Closure Monad is a special case of MonadReader.

Clone this wiki locally