<div><div dir="auto">Join actually also comes up in compiler engineering!</div></div><div dir="auto"><br></div><div dir="auto">Most normalized compiler reps: notably anf and cps, have a sort of flatness condition where you can’t have nested subexpressions (aka in many cases in strict languages this is where evaluation order becomes explicit ) and the join operation corresponds to a step in the flattening process for nested expression syntax when you do compiler transformations in this setting. </div><div dir="auto"><br></div><div dir="auto">This is in fact exactly why it’s pretty brutal to write the monad for an anf or cps syntax , you’re essentially specifying subexpression evaluation order for all pairs of syntax constructors! </div><div dir="auto"><br></div><div dir="auto"> And while join is not at the moment in the Monad typeclass because of newtype stuff, writing these monad instances is way saner in terms of the join operators rather than in terms of bind. At least in my biased perspective ;)</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 14, 2019 at 4:37 AM Georgi Lyubenov <<a href="mailto:godzbanebane@gmail.com">godzbanebane@gmail.com</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">In general, if you want to <b>dynamically generate</b> actions depending on the result of an earlier action you will always encounter join/(>>=).<br>For example (with ReadPrec/Parser): <br>I want to first parse a character, and then parse the same character two more times.<br>numberAndThenThatManyAs = join (fmap (\c -> satisfy (==c) *> satisfy (==c)) char)<br><br>Of note:<br>* The example is contrived for simplicity's sake, but you do really need a Monad (and hence join) to perform stuff like this in general. A more practical example would be parsing command-line options that depend on previous options.<br>* Obviously it's way more humane to write this with do-syntax. (or (>>=) or something) - do { c <- char; satisfy (==c); satisfy (==c) }<br>* I'm not actually sure whether you need a Monad in this situation, maybe you could get away with just <a href="http://hackage.haskell.org/package/selective-0.3" target="_blank">selectives</a><br><br>=======</div><div dir="ltr"><br>Georgi</div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div></div>