diff options
Diffstat (limited to 'week4')
-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))])
|