<div dir="ltr"><div>Another way to do this would be to sort the sub lists according to what they contain (the list heads) and then their length (to resolve ties).</div><div>You could then use nubBy with “(==) `on` head” to remove lists and only be left with the longest lists. Since nub[By] <span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px;line-height:18.200000762939453px">keeps only the first occurrence of each element</span> when there are duplicates, “comparing length” is flipped – meaning that longer lists come first. This gives us the following function: </div>

<div><br></div>    nubBy ((==) `on` head) . sortBy (comparing head <> flip (comparing length)) . group<br><div><br></div><div>Where (<>) is from Data.Monoid. An explanation of using monoids to build sorting combinators can be found in this reddit post [note that the author uses (++) for (<>)]:</div>

<div><a href="http://www.reddit.com/r/programming/comments/7cf4r/monoids_in_my_programming_language/c06adnx">http://www.reddit.com/r/programming/comments/7cf4r/monoids_in_my_programming_language/c06adnx</a></div><div><br>

</div><div class="gmail_extra">-- <br>Erlend Hamberg<br><a href="mailto:ehamberg@gmail.com">ehamberg@gmail.com</a><br>
</div></div>