12
What is a good way to represent the type LoL a, being a list of lists
of ... of a? The nesting level is arbitrary, but uniform over all
elements of the outer list.
The case I have in mind is to apply a grouping on the members of a list, and then to apply a next grouping on each subgroup, and so on. It is not known up front how many groupings one will have to apply. Hence:
rGroupBy :: [(a -> a -> Bool)] -> [a] -> [...[a]...]
Extra brownie points for the type signature of rGroupBy ;-)
Example:
Suppose deweyGroup i groups the elements based on the i-th number
rGroupBy [deweyGroup 1, deweyGroup 2]
["1.1", "1.2.1", "1.2.2", "2.1", "2.2", "3"]
gives:
[ [ [ "1.1" ], [ "1.2.1", "1.2.2" ] ],
[ [ "2.1" ], [ "2.2" ] ],
[ [ "3" ] ]
]
Postscript
One day later, we have 4 excellent and complementary solutions. I'm very pleased with the answers; thank you all.