<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""> I have </div><div class=""><div style="color: rgb(51, 51, 51); background-color: rgb(253, 246, 227); font-family: Menlo, Monaco, "Courier New", monospace; font-size: 20px; line-height: 30px; white-space: pre;" class=""><div class="">sumIs2020P1' xs <span style="color: #859900;" class="">=</span> <span style="color: #859900;" class="">do</span> </div><div class=""> x <span style="color: #859900;" class=""><-</span> xs</div><div class=""> y <span style="color: #859900;" class=""><-</span> xs</div><div class=""> guard (x <span style="color: #859900;" class="">+</span> y <span style="color: #859900;" class="">==</span> <span style="color: #d33682;" class="">2020</span>)</div><div class=""> pure (x,y)</div></div></div><div class=""><br class=""></div><div class="">which has been desugared from a list comprehension</div><div class="">I would like to reduce this even more using >>= </div><div class="">So I do</div><div class=""><div style="color: rgb(51, 51, 51); background-color: rgb(253, 246, 227); font-family: Menlo, Monaco, "Courier New", monospace; font-size: 20px; line-height: 30px; white-space: pre;" class=""><div class="">sumIs2020P1'' xs <span style="color: #859900;" class="">=</span> (a,b) <span style="color: #859900;" class="">where</span></div><div class=""> (a,b)<span style="color: #859900;" class="">:</span>rest <span style="color: #859900;" class="">=</span> filter (<span style="color: #859900;" class="">\</span>(x,y) <span style="color: #859900;" class="">-></span> x <span style="color: #859900;" class="">+</span> y <span style="color: #859900;" class="">==</span> <span style="color: #d33682;" class="">2020</span>) pairs </div><br class=""><div class=""> pairs <span style="color: #859900;" class="">=</span> xs <span style="color: #859900;" class="">>>=</span> <span style="color: #859900;" class="">\</span>x <span style="color: #859900;" class="">-></span> </div><div class=""> xs <span style="color: #859900;" class="">>>=</span> <span style="color: #859900;" class="">\</span>y <span style="color: #859900;" class="">-></span> </div><div class=""> pure (x,y)</div><div class=""></div></div></div><div class=""><br class=""></div><div class="">but really I would like the guard to be within the >>= sections but I could not work out </div><div class="">how to do it!</div><div class="">i.e. I’m looking for something like (pseudo code)</div><div class=""><br class=""></div><div class=""><div style="caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-family: Menlo, Monaco, "Courier New", monospace; font-size: 20px; white-space: pre; background-color: rgb(253, 246, 227);" class="">pairs <span style="color: rgb(133, 153, 0);" class="">=</span> xs <span style="color: rgb(133, 153, 0);" class="">>>=</span> <span style="color: rgb(133, 153, 0);" class="">\</span>x <span style="color: rgb(133, 153, 0);" class="">-></span> </div><div style="caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-family: Menlo, Monaco, "Courier New", monospace; font-size: 20px; white-space: pre; background-color: rgb(253, 246, 227);" class=""> xs <span style="color: rgb(133, 153, 0);" class="">>>=</span> <span style="color: rgb(133, 153, 0);" class="">\</span>y <span style="color: rgb(133, 153, 0);" class="">-></span> </div><div style="caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-family: Menlo, Monaco, "Courier New", monospace; font-size: 20px; white-space: pre; background-color: rgb(253, 246, 227);" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>if (x + y == 2020) then pure (x,y) else DO_NOTHING</div><div style="caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); font-family: Menlo, Monaco, "Courier New", monospace; font-size: 20px; white-space: pre; background-color: rgb(253, 246, 227);" class=""> </div></div><div class="">which would then allow the filter to be removed. </div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Many Thanks</div><div class=""><br class=""></div><div class="">Mike</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class="">
<div>Dr Mike Houghton</div><div><br class=""></div><div><a href="mailto:mike_k_houghton@yahoo.co.uk" class="">mike_k_houghton@yahoo.co.uk</a></div><div class=""><br class=""></div><br class="Apple-interchange-newline">
</div>
<br class=""></div></body></html>