I'm pretty new to SML and I have been trying to find some function that generates all the sublists of a list in order recursively ie [1, 2, 3] -> [[], [1], [2], [3], [1, 2], [1, 2, 3], [1, 3], [2, 3]] but [2,1] for example wouldnt be a sublist since it is out of order. This would be a function of type int list -> int list list or something of the sort where the output contains all the sublists. I've been trying to rack my brain around this and haven't really come up with any ideas on how to do this. Some help would be much appreciated!
Asked
Active
Viewed 287 times
0
-
This list of lists is called the [power set](https://en.wikipedia.org/wiki/Power_set). When you know the right terminology, it becomes easier to google an answer. Incidentally, [this question was asked and answered](https://stackoverflow.com/questions/48571656/implementing-powerset-function-in-ml-using-only-map-and-folds) for SML in-depth before. – sshine Feb 25 '21 at 07:30
-
Here is [another SML powerset Q&A](https://stackoverflow.com/questions/48605564/smlnj-powerset-function), and [another SML powerset Q&A](https://stackoverflow.com/questions/19330112/simple-functions-for-sml-nj). – sshine Feb 25 '21 at 08:07