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 | |
parent | 5.4 is raar idd (diff) |
mooiere powerset
-rw-r--r-- | week4/mart/StdSet.dcl | 2 | ||||
-rw-r--r-- | week4/mart/StdSet.icl | 10 |
2 files changed, 5 insertions, 7 deletions
diff --git a/week4/mart/StdSet.dcl b/week4/mart/StdSet.dcl index 6cad7f1..0c702ca 100644 --- a/week4/mart/StdSet.dcl +++ b/week4/mart/StdSet.dcl @@ -22,4 +22,4 @@ product :: (Set a) (Set b) -> Set (a,b) instance zero (Set a)
instance == (Set a) | Eq a
-powerSet :: (Set a) -> Set (Set a)
+powerSet :: (Set a) -> Set (Set a) | Eq a
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))])
|