[Haskell-cafe] Generic Sorting

Henning Thielemann lemming at henning-thielemann.de
Sat Nov 14 08:11:46 UTC 2020


On Fri, 13 Nov 2020, Henry Laxen wrote:

> Good evening Haskellers.
>
> I've done some searching but so far haven't found anything, which make
> me think this probably isn't possible.  I am wondering if it is
> possible to do a "Generic Sort" on multilevel data structures.
> Suppose you have something like:
>
> data A = A Int [Int]
> data B = B Int [A]
>
> a1 = A 2 [2,1]
> a2 = A 1 [4,3]
> b  = B 1 [a1,a2]
>
> genericSort b = B 1 [A 1 [3,4], A 2 [1,2]]
>
> note that not only are the A's sorted, but the list inside each A is
> sorted.  It "sorted all the way down".  Has Edward written such a
> thing yet? ;-) His "discrimination" library doesn't do this, in case
> you're wondering.  Any ideas?

You could first sort the structures and then fill it with a sorted 
flattened list.


More information about the Haskell-Cafe mailing list