[Haskell-beginners] short-circuit like Maybe monad with a difference
Dennis Raddle
dennis.raddle at gmail.com
Fri Sep 30 20:28:03 UTC 2016
I have a function 'evalRule' that applies rules to steps in a backtracking
search optimization problem and evaluates the step's fitness or decides
that it must be eliminated entirely.
In the following, a result of Nothing means "eliminate the step," Just x
means the step has fitness score x.
evalRule :: Rule -> Step -> Maybe Double
I would like to write a function that applies a bunch of rules but
short-circuits the computation if it hits Nothing. However, unlike the way
the Maybe monad works, I want to know the partial results.
In the following, the rules are applied in order and the "Just" results are
collected up the point where a rule returns Nothing.
evalRules :: [Rule] -> Step -> [Double]
What's a nice way to do this?
D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160930/93c10e22/attachment.html>
More information about the Beginners
mailing list