diff options
author | Camil Staps | 2016-02-02 19:24:50 +0100 |
---|---|---|
committer | Camil Staps | 2016-02-02 19:24:50 +0100 |
commit | a7d7542dc646a5fd124ef71e71ce260889f1701b (patch) | |
tree | 04ed89503bbb3cc9933273a1326a53ca724c3492 /fp2/week3/camil/StdDynSet.icl | |
parent | week6 camil: working positioning of lines by putting empties at left and righ... (diff) |
Diffstat (limited to 'fp2/week3/camil/StdDynSet.icl')
-rw-r--r-- | fp2/week3/camil/StdDynSet.icl | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/fp2/week3/camil/StdDynSet.icl b/fp2/week3/camil/StdDynSet.icl deleted file mode 100644 index 576bec9..0000000 --- a/fp2/week3/camil/StdDynSet.icl +++ /dev/null @@ -1,62 +0,0 @@ -// Mart Lubbers s4109503, Camil Staps s4498062 - -implementation module StdDynSet - -import StdEnv -import StdMaybe -import StdDynamic - -isEqual:: Dynamic t -> Bool | Set t -isEqual (x :: t^) a = x == a -isEqual _ _ = False - -class Set a | TC, ==, toString a - -:: Set = Set [(Dynamic, Dynamic -> Bool, String)] - -instance zero Set -where zero = Set [] - -instance toString Set -where toString (Set [(_,_,a):as]) = "{" +++ a +++ (foldl (+++) "" ["," +++ s \\ (_,_,s) <- as]) +++ "}" - -instance == Set -where == a b = nrOfElts a == nrOfElts b && isSubset a b - -toSet :: a -> Set | Set a -toSet e = Set [(dynamic e, \x = isEqual x e, toString e)] - -nrOfElts :: Set -> Int -nrOfElts (Set a) = length a - -isEmptySet :: Set -> Bool -isEmptySet a = (nrOfElts a) == 0 - -memberOfSet :: a Set -> Bool | Set a -memberOfSet _ (Set []) = False -memberOfSet x (Set [(y,_,_):ys]) = isEqual y x || memberOfSet x (Set ys) - -dynMemberOfSet :: Dynamic Set -> Bool -dynMemberOfSet _ (Set []) = False -dynMemberOfSet x (Set [(_,eq,_):ys]) = eq x || dynMemberOfSet x (Set ys) - -isSubset :: Set Set -> Bool -isSubset a b = (nrOfElts a) == (nrOfElts (intersection a b)) - -isStrictSubset :: Set Set -> Bool -isStrictSubset a b = isSubset a b && nrOfElts a < nrOfElts b - -union :: Set Set -> Set -union (Set a) (Set b) = Set (a ++ (fromSet (without (Set b) (Set a)))) -where - fromSet :: Set -> [(Dynamic, Dynamic -> Bool, String)] - fromSet (Set x) = x - -intersection :: Set Set -> Set -intersection as (Set []) = as -intersection (Set as) (Set bs) = Set [(a,eq,ts) \\ (a,eq,ts) <- as | dynMemberOfSet a (Set bs)] - -without :: Set Set -> Set -without (Set as) (Set bs) = Set [(a,eq,ts) \\ (a,eq,ts) <- as | not (dynMemberOfSet a (Set bs))] - -Start = toString (union (toSet 1) (toSet 2)) |