ekmett / ersatz

A monad for interfacing with external SAT solvers
Other
62 stars 15 forks source link

Monomorphise `decode`/`solveWith` to `Maybe` (#61) and fix #60/#76 #77

Closed RyanGlScott closed 9 months ago

RyanGlScott commented 9 months ago

This PR is a collection of patches that, when taken together, fix #60, #61, and #76:

Use Maybe (instead of an arbitrary MonadPlus) in decode and solveWith

As noted in https://github.com/ekmett/ersatz/issues/61, it's not clear what the intended behavior of decode/solveWith should be for MonadPlus instances like []. Moreover, the internals of ersatz more-or-less already assume that we are working in Maybe, and nearly all uses of solveWith in the wild pick Maybe to begin with. To avoid potential confusion, let's just concretize decode/solveWith to always work over Maybe.

Fixes https://github.com/ekmett/ersatz/issues/61.

Return consistent results for unconstrained literals

Previously, ersatz would always decode every unconstrained Literal to False, which could produce inconsistent results for things like do { b <- exists; pure [b, not b] }, which would decode to [False, False]. We now adopt the convention that unconstrained non-negative Literals always decode to False, and that unconstrained negative Literals always decode to True, so the example above now decodes to [False, True].

Fixes https://github.com/ekmett/ersatz/issues/60. Fixes https://github.com/ekmett/ersatz/issues/76.

Provide Haddocks for solveWith

The exact meaning of what solveWith returns is not obvious at a first glance. This patch provides some Haddocks for solveWith that better explains this and provides a complete example of how to use solveWith.