F#迭代N维

时间:2016-06-13 10:16:47

标签: recursion f# iteration traversal

在F#中迭代N维的好方法是什么?具体来说,我想迭代列表列表中的级别并显示不同的路径。这是一个关于我想在任意列表维度中做什么的简单例子。

let L1 = ["A"; "B"]
let L2 = ["C"; "D"]
let L3 = ["E"; "F"; "G"]

let pathSteps = [L1; L2; L3]

let printAllPaths =
    let allPaths =
        seq{
            for c1 in L1 do
                for c2 in L2 do
                    for c3 in L3 do
                         yield [c1; c2; c3] 
           }
    for ls in allPaths do
        ls
        |> Seq.toList
        |> printfn "%A"

0 个答案:

没有答案