<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>We continue the separation of ascending subequences...<br>
</p>
<div class="moz-cite-prefix">Le 24/03/2023 à 22:10, Johannes
Waldmann a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:53e13b10-b019-7311-13cf-e7208be44bfe@htwk-leipzig.de">@Jerzy
: I like your plan to use combinators.
<br>
Then let's remove (visible) recursion completely:
<br>
<br>
<b><font face="Courier New, Courier, monospace">map (map fst ) $
groupBy (const snd)
<br>
$ zip xs ( True : zipWith (<=) xs (tail xs))
</font></b><br>
</blockquote>
<p>Hmmm, I didn't find it... Perhaps at that time I didn't acquire
yet a sufficient level of perversion...</p>
<p>Well, the truth is that I had problems with groupBy! People
discovered that the "standard" groupBy, which was sometimes
thought of as an iterator which compared neighbours, didn't. If it
behaved as some people wished, then we could simply write</p>
<p><b><font face="Courier New, Courier, monospace">groupBy (<)
[3,4,5,6,2,3,4,1,2,1]</font></b></p>
<p>and get : <b><font face="Courier New, Courier, monospace">[[3,4,5,6],[2,3,4],[1,2],[1]]
</font></b><br>
</p>
<p>Actually ... It works!! But unfortunately this is accidental. The
following example doesn't:</p>
<p><b><font face="Courier New, Courier, monospace">groupBy (<)
[5,3,1,2,8,6,3,7,2,5,9]<br>
[[5],[3],[1,2,8,6,3,7,2,5,9]]</font></b><br>
</p>
<p>This was discovered apparently more than once. Look up <br>
</p>
<p><b><font face="Courier New, Courier, monospace"><a class="moz-txt-link-freetext" href="http://brandon.si/code/an-alternative-definition-for-datalistgroupby/">http://brandon.si/code/an-alternative-definition-for-datalistgroupby/</a></font></b></p>
<p>Brandon Simmons gives his alternative definition, which defines
its own version of span:</p>
<p><b><font face="Courier New, Courier, monospace">groupBy' :: (a
-> a -> Bool) -> [a] -> [[a]]<br>
groupBy' c [] = []<br>
groupBy' c (a:as) = (a:ys) : groupBy' c zs<br>
where (ys,zs) = spanC a as<br>
spanC _ [] = ([], [])<br>
spanC a' (x:xs)<br>
| a' `c` x = let (ps,qs) = spanC x xs<br>
in (x:ps,qs)<br>
| otherwise = ([], x:xs)</font></b></p>
<p>which yields the following result:</p>
<p><b><font face="Courier New, Courier, monospace">groupBy' (<)
[5,3,1,2,8,6,3,7,2,5,9]<br>
[[5],[3],[1,2,8],[6],[3,7],[2,5,9]]</font></b></p>
<p>Look also:</p>
<p><b><font face="Courier New, Courier, monospace"><a class="moz-txt-link-freetext" href="https://hackage.haskell.org/package/groupBy-0.1.0.0/docs/Data-List-GroupBy.html">https://hackage.haskell.org/package/groupBy-0.1.0.0/docs/Data-List-GroupBy.html</a></font></b></p>
<p>by Donnacha Oisín Kidney (c) 2018; but I didn't verify his
variant.</p>
<p>==</p>
<p>Jerzy Karczmarczuk</p>
<p><br>
</p>
<p></p>
<p></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>