so far I can't figure out a way to write powerset in SML :(.
I see a pattern for example

powerset([1,2,3]) is

[] [1]
[2] [1,3]
[3] [1,2]
[2,3] [1,2,3]

Here's what I have come up with:

fun add(a,L)= [a]@L

fun ps(L)=
ps(tl L)@add(hd L, ps(tl L));

Any help appreciated.

Recommended Answers

All 2 Replies

What's the powerset of the empty set?

Given x and given the powerset of xs, what's the powerset of (x :: xs)?

Bam, use recursion.

thanks i figured it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.