summaryrefslogtreecommitdiff
path: root/week4/mart/StdSet.icl
diff options
context:
space:
mode:
Diffstat (limited to 'week4/mart/StdSet.icl')
-rw-r--r--week4/mart/StdSet.icl10
1 files changed, 4 insertions, 6 deletions
diff --git a/week4/mart/StdSet.icl b/week4/mart/StdSet.icl
index a14e6ba..ecb2e60 100644
--- a/week4/mart/StdSet.icl
+++ b/week4/mart/StdSet.icl
@@ -48,9 +48,7 @@ where zero = Set []
instance == (Set a) | Eq a
where (==) s1 s2 = isSubset s1 s2 && isSubset s2 s1
-powerSet :: (Set a) -> Set (Set a)
-powerSet (Set a) = Set [(Set x) \\ x <- powerSet2 a]
-where
- powerSet2 :: [a] -> [[a]]
- powerSet2 [] = [[]]
- powerSet2 [e:xs] = (powerSet2 xs) ++ [[e:x] \\ x <- powerSet2 xs]
+powerSet :: (Set a) -> Set (Set a) | Eq a
+powerSet (Set []) = Set [(Set [])]
+powerSet (Set [e:xs]) = union (powerSet (Set xs))
+ (Set [union (Set [e]) x \\ x <- fromSet (powerSet (Set xs))])