<p dir="ltr">That's what I was thinking, but I couldn't figure out if I wanted MonadPlus, Alternative or maybe Monoid because they all have zero elements. </p>
<br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 20, 2017, 21:52 Joshua Grosso <<a href="mailto:jgrosso1@asu.edu">jgrosso1@asu.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_extra">Could MonadPlus (with mzero) or Alternative (with empty) provide the termination condition, if this pattern turned out to be more generally useful?</div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">Joshua Grosso</div></div></div><div dir="ltr"><div class="gmail_extra">
<br><div class="gmail_quote">On Thu, Jul 20, 2017 at 7:16 PM, Jeff Clites <span dir="ltr"><<a href="mailto:jclites@mac.com" target="_blank">jclites@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div></div><div>Also this pattern does seem Maybe-specific, in that for the general Monad case there's not an obvious termination condition.</div><span class="m_882358674580095546gmail-HOEnZb"><font color="#888888"><div><br></div><div>JEff</div></font></span><div><div class="m_882358674580095546gmail-h5"><div><br>On Jul 20, 2017, at 11:03 AM, Rein Henrichs <<a href="mailto:rein.henrichs@gmail.com" target="_blank">rein.henrichs@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">This is about as good as you can do. The monad-loops package provides a variety of similar combinators, generally implemented in similar ways, but not this specific combinator. The downside of this combinator is that it is partial: it will run forever without producing anything if f never gives a Nothing.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 20, 2017 at 10:27 AM Jake <<a href="mailto:jake.waksbaum@gmail.com" target="_blank">jake.waksbaum@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I have a function f :: a -> Maybe a that I want to feed into itself with some initial input until it returns Nothing.<div><div><br><div>untilNothing :: (a -> Maybe a) -> a -> a<br></div><div>untilNothing f x = case f x of</div></div></div><div> Just x' -> untilNothing f x'</div><div> Nothing -> x</div><div><br></div><div>Is there a better way to do this? I feel like there is something more general going on with Monads being fed into themselves, but maybe I'm wrong. Thoughts?</div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Haskell-Cafe mailing list</span><br><span>To (un)subscribe, modify options or view archives go to:</span><br><span><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a></span><br><span>Only members subscribed via the mailman list are allowed to post.</span></div></blockquote></div></div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div></div></blockquote></div>