[Haskell-cafe] Powerset of a set

Albert Y. C. Lai trebla at vex.net
Mon Sep 14 19:23:44 UTC 2015


On 2015-09-14 02:57 PM, JORGE MALDONADO wrote:
> The powerset of set s is a set containing all subsets of s.
> I need a clue on how to write Haskell code to get the superset of a 
> set using direct recursion and list comprehension.

"superset"? "subsets"?

To compute all subsets of x:xs, i.e., "powerset (x:xs) = ?" :

Suppose powerset xs correctly answers you all subsets of xs. How do you 
build upon its answer to obtain all subsets of x:xs?

Basically, each subset of xs is also a subset of x:xs, so you want to 
include them in your answer for x:xs.

On top of that, for each subset of xs, you can insert x and get a subset 
of x:xs, too.

Does this cover all cases?


More information about the Haskell-Cafe mailing list