&gt; observe $ flip runStateT 10 $ (put 0 &gt;&gt; mzero) &lt;|&gt; modify (+3)<br>
 &gt;   ((),13)<br><br>If the only thing you need is backtracking, using LogicT might be a little overkill, using Maybe in the bottom of you monad stack suits just fine:<br><br>case flip runStateT 10 $ (put 0 &gt;&gt; mzero) &lt;|&gt; modify (+3) of<br>

    Just x -&gt; ....<br>    Nothing -&gt; ....<br><br><div class="gmail_quote">2012/5/27 Roman Cheplyaka <span dir="ltr">&lt;<a href="mailto:roma@ro-che.info" target="_blank">roma@ro-che.info</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

* L Corbijn &lt;<a href="mailto:aspergesoepje@gmail.com">aspergesoepje@gmail.com</a>&gt; [2012-05-27 14:21:39+0200]<br>
<div class="im">&gt; The solution I&#39;ve in mind depends on the stack being pure. When the<br>
&gt; monad stack is pure a rule can be applied, returning a maybe value (or<br>
&gt; having a MaybeT wrapper) and when returning Nothing (failed rule)<br>
&gt; reverting the stack to it&#39;s point before applying the rule.<br>
&gt;<br>
&gt; As I&#39;m not quite sure about the design (nor good at software design)<br>
&gt; I&#39;ve some questions about this approach.<br>
&gt; 1. Is there a better approach then using a state monad for building<br>
&gt; the &#39;products&#39;?<br>
<br>
</div>If you need to interleave building your &quot;products&quot; and analyzing them,<br>
State seems a reasonable choice here.<br>
<div class="im"><br>
&gt; 2. My solution with saving/reverting monad-stacks seems quite a<br>
&gt; hassle/hack, so is it a good approach or is there something better?<br>
<br>
</div>You can use a backtracking monad here ([] or Logic).<br>
<br>
The key thing is to put the backtracking monad in the bottom of your<br>
stack (everything above it will be restored on mzero). On the other<br>
hand, if you want some &quot;global&quot; effects that should not be restored, you<br>
can put corresponding monads below LogicT in the stack.<br>
<br>
Example:<br>
<br>
    &gt; observe $ flip runStateT 10 $ (put 0 &gt;&gt; mzero) &lt;|&gt; modify (+3)<br>
    ((),13)<br>
<br>
Note that &quot;put 0&quot; had no effect here, because it was followed by mzero.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Roman I. Cheplyaka :: <a href="http://ro-che.info/" target="_blank">http://ro-che.info/</a><br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>