べき集合

30分プログラム、その730。べき集合をもとめる関数。

前にべき集合を一行で求めるコードを見たことあるような気がするけど、思い出せなかったし、辿りつけなかった。ちぇー。

使い方

Prelude> powerSet [1..3]
[[1,2,3],[2,3],[1,3],[3],[1,2],[2],[1],[]]

ソースコード

powerSet:: [a] -> [[a]]

powerSet [] = [[]]
powerSet (x:xs) = concat [ [ (x : ys),  ys ] | ys <- powerSet xs ]