I am trying to perform some small tasks in F # to help get a language descriptor.
I would like to write a function that takes an n-dimensional list and returns a 1-dimensional list containing all the elements from each dimension.
For example, if the input was the following 3-dimensional list: [[[1; 2]; [3; 4]]; [[5; 6]; [7; 8]]], output be: [1; 2; 3; 4; 5; 6; 7; 8]
For two-dimensionality → 1-dimensional function is quite simple:
let coalesce list= List.collect(fun item -> item) list
Here is my attempt to generalize this to n-sizes:
let rec coalesce (list, dimension) =
if dimension = 1 then list
else coalesce (List.collect(fun item -> item) list, dimension - 1)
When trying to compile the following error:
error FS0001: type mismatch. Waiting for a list of lists
but considering a list
The resulting type would be infinite when combining "a" and "list"
The problem is here:
List.collect(fun item -> item) list
, - . ?