I'm currently using the following function:
let rec combine xss = function
| [] -> []
| ys::yss -> List.map ((@) ys) xss @ combine xss yss
It is combining two lists of lists in the following way:
combine [["x"];["a"];["c"]] [["u"];["h"];["p"]]
gives this result:
[["u"; "x"]; ["u"; "a"]; ["u"; "c"]; ["h"; "x"]; ["h"; "a"]; ["h"; "c"];
["p"; "x"]; ["p"; "a"]; ["p"; "c"]]
This is totally as I want it, however.. I'm currently using this method a lot and the data has become so vast that the program currently aren't able to run.
Is there a way for this to run fast for lists of lists? The lists contain about 1100 elements and the lists inside contain about 10 elements each. Just a little speed up is appreciated!
EDIT:
The above listed example might not be that good, it was just to show what it is doing. The data I'm actually using combines lists of lists of this predifined type:
type atom = ANum of float | AExponent of string * int
| ADiv of atom list list * atom list list | ARoot of expr * int
The expr
type used here is of no interest for the combining method.
Specifically in my code I could be doing something as terrible as (in a match):
| ADiv(all3,all4) -> ADiv((combine all2 all3)@(combine all1 all4),combine all2 all4)
With allx
being atom list list
as the above type states.
Does any of this explain it enough?