4
下面的函數返回set(list)的powerset。F#Powerset函數
let rec powerset = function
| [] -> [[]]
| x::xs -> List.collect (fun sub -> [sub; x::sub]) (powerset xs)
我不明白爲什麼它的工作原理。我瞭解遞歸。我也理解List.collect是如何工作的。我知道遞歸將繼續,直到powerset的一個實例返回[[]]。但是,我試圖追蹤那個點之後的返回值,並且我從來沒有獲得完整的功率集。
很好的解釋!現在我明白其背後的原因。非常感謝。 – topstarterrhp