Constructing/flattening a list of lists in ATS

89 Views Asked by At

How can I form a list of lists in ATS?

For instance, I would like to have a list consisting of all the permutations of the list (1, 2, 3).

In addition, how can I flatten a list of lists into a list?

1

There are 1 best solutions below

0
On

Say that you want to use list0 (un-indexed):

val xs1 = g0ofg1($list{int}(1,2,3))
val xs2 = g0ofg1($list{int}(1,3,2))
val xs3 = g0ofg1($list{int}(2,1,3))
val xs4 = g0ofg1($list{int}(2,3,1))
val xs5 = g0ofg1($list{int}(3,1,2))
val xs6 = g0ofg1($list{int}(3,2,1))
val xss = g0ofg1($list{list0(int)}(xs1, xs2, xs3, xs4, xs5, xs6))

For flattening, you can use list0_concat:

fun{a:t@ype}
flatten(xss: list0(list0(a))): list0(a) = list0_concat<a>(xss)