diff options
author | Mart Lubbers | 2015-03-03 12:37:56 +0100 |
---|---|---|
committer | Mart Lubbers | 2015-03-03 12:37:56 +0100 |
commit | d21ead92c20299ce914b1e3a7663990f9a3e85f1 (patch) | |
tree | 27617ba1602fe73fca4e90b135ac31978f0e1463 /week4/mart/StdSet.icl | |
parent | 5.4 is raar idd (diff) |
mooiere powerset
Diffstat (limited to 'week4/mart/StdSet.icl')
-rw-r--r-- | week4/mart/StdSet.icl | 10 |
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))])
|