is there any fold in Haskell that will balance the grouping so as to minimize depth? i.e. for 4 elements it'd do (a <> b) <> (c <> d)
@natty @mildsunrise ohh right, it was in the sorting algorithms post:
https://apfelmus.nfshost.com/articles/quicksearch.html#message-1---mergesort
they just iteratively decimate the list until it is a singleton
@monoidmusician @natty amusingly my monoid is also merge, but I am not trying to implement a mergesort (instead I have a bunch of equally long sorted lists that i need to merge into a single one)
@mildsunrise @monoidmusician @natty I think you can do the same trick though? Merge adjacent pairs of lists, then merge adjacent pairs of the result of the first pass, and so on recursively.
That said, I wonder if it's any better to put all your lists into a priority queue ordered by the next element of each list? I learned that trick from the Python standard library and I dunno if it works as well when the data structure is immutable/persistent.
@mildsunrise@tech.lgbt sounds a bit difficult on a linked list, if it doesn't know the length ahead of time
Maybe the source for quick sort would have one?