<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">Le 24/03/2023 à 00:51, Anthony Clayden
a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:CABU_mxiBJsyRZ5OoGoxbdE-C65QQ3TOmJs1RweRGnnp7o9=YNw@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>
<pre style="white-space:pre-wrap;color:rgb(0,0,0)">On Thu, Mar 16, 2023, 20:33 Todd Wilson <<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" moz-do-not-send="true">twilson at csufresno.edu</a>> wrote:
</pre>
> ...</div>
<div><br>
</div>
> <span style="color:rgb(0,0,0);white-space:pre-wrap">My question: can we do better than this? It seems that this solution is</span>
<pre style="white-space:pre-wrap;color:rgb(0,0,0)">> constantly building and breaking apart pairs. (Or is it, when optimized?)
</pre>
<div>I don't think we can do better (as others have commented).
Laziness is a benefit for peeling off only the beginning(s) of
possibly-infinite (sub-)lists.</div>
</div>
</blockquote>
<p>I believe that there is more to say about this function "runs"
than just concentrate on the issue of rebuilding the result list.
This is one of quite classical pedagogical exercises in list
processing in Haskell, and has been discussed at least twice on
StackOverflow<br>
</p>
<p>E.g.,<br>
</p>
<p><a class="moz-txt-link-freetext" href="https://stackoverflow.com/questions/14403293/need-to-partition-a-list-into-lists-based-on-breaks-in-ascending-order-of-elemen">https://stackoverflow.com/questions/14403293/need-to-partition-a-list-into-lists-based-on-breaks-in-ascending-order-of-elemen</a></p>
<p>Such recursive schemas as proposed by Todd Wilson should be -- of
course -- mastered, but, suppose that your students have already
heard about combinators, and all them zips, folds, maps, etc. ,
and they need now some training. What about the following? <br>
<br>
runs xs = ru (zip xs (False : zipWith (<) xs (tail xs)))<br>
where<br>
ru (z:zq) = <br>
let (a,b) = span snd zq<br>
in (map fst (z:a) : ru b)<br>
ru [] = []</p>
<p>When I gave this exercise (some centuries ago), I didn't care
about having manufactured auxiliary structures, but I gently
asked the students to <i><b>understand</b></i> this code, to
realize that it is easy to "transmute" a (binary) relation between
neighbours in a list into a unary predicate, which could then be
used by <b><font face="Courier New, Courier, monospace">span</font></b>.
<br>
</p>
<p>Jerzy Karczmarczuk</p>
<p><br>
</p>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br /><table style="border-top: 1px solid #D3D4DE;"><tr><td style="width: 55px; padding-top: 13px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://s-install.avcdn.net/ipm/preview/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;"/></a></td><td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Sans virus.<a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a></td></tr></table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div>
<br>
<br>
</body>
</html>