Verified Commit aaeacbbc authored by Camil Staps's avatar Camil Staps 🚀

Remove redundant type contexts from Data.Set

parent 9df66b44
Pipeline #8159 passed with stage
in 1 minute and 56 seconds
...@@ -68,7 +68,7 @@ size s :== case s of ...@@ -68,7 +68,7 @@ size s :== case s of
/** /**
* Is the element in the set? * Is the element in the set?
*/ */
member :: !a !(Set a) -> Bool | < a & == a member :: !a !(Set a) -> Bool | < a
/** /**
* Checks if an element is not in the set. * Checks if an element is not in the set.
...@@ -82,7 +82,7 @@ notMember x t :== not (member x t) ...@@ -82,7 +82,7 @@ notMember x t :== not (member x t)
*/ */
isSubsetOf t1 t2 :== (size t1 <= size t2) && (isSubsetOfX t1 t2) isSubsetOf t1 t2 :== (size t1 <= size t2) && (isSubsetOfX t1 t2)
isSubsetOfX :: !(Set a) !(Set a) -> Bool | < a & == a isSubsetOfX :: !(Set a) !(Set a) -> Bool | < a
/** /**
* Is t1 a proper subset of t2? * Is t1 a proper subset of t2?
...@@ -103,12 +103,12 @@ singleton :: !u:a -> w:(Set u:a), [w <= u] ...@@ -103,12 +103,12 @@ singleton :: !u:a -> w:(Set u:a), [w <= u]
* Insert an element in a set. * Insert an element in a set.
* If the set already contains an element equal to the given value, it is replaced with the new value. * If the set already contains an element equal to the given value, it is replaced with the new value.
*/ */
insert :: !a !.(Set a) -> Set a | < a & == a insert :: !a !.(Set a) -> Set a | < a
/** /**
* Delete an element from a set. * Delete an element from a set.
*/ */
delete :: !a !.(Set a) -> Set a | < a & == a delete :: !a !.(Set a) -> Set a | < a
/** /**
* The minimal element of a set. * The minimal element of a set.
...@@ -185,13 +185,13 @@ intersections :: ![Set a] -> Set a | < a & == a ...@@ -185,13 +185,13 @@ intersections :: ![Set a] -> Set a | < a & == a
/** /**
* Filter all elements that satisfy the predicate. * Filter all elements that satisfy the predicate.
*/ */
filter :: !(a -> Bool) !(Set a) -> Set a | < a & == a filter :: !(a -> Bool) !(Set a) -> Set a | < a
/** /**
* Partition the set into two sets, one with all elements that satisfy the * Partition the set into two sets, one with all elements that satisfy the
* predicate and one with all elements that don't satisfy the predicate. * predicate and one with all elements that don't satisfy the predicate.
*/ */
partition :: !(a -> Bool) !(Set a) -> (!Set a, !Set a) | < a & == a partition :: !(a -> Bool) !(Set a) -> (!Set a, !Set a) | < a
/** /**
* Split a set in elements less and elements greater than a certain pivot. * Split a set in elements less and elements greater than a certain pivot.
...@@ -200,13 +200,13 @@ partition :: !(a -> Bool) !(Set a) -> (!Set a, !Set a) | < a & == a ...@@ -200,13 +200,13 @@ partition :: !(a -> Bool) !(Set a) -> (!Set a, !Set a) | < a & == a
* @param The set. * @param The set.
* @return A tuple of two sets containing small and large values. * @return A tuple of two sets containing small and large values.
*/ */
split :: !a !(Set a) -> (!Set a, !Set a) | < a & == a split :: !a !(Set a) -> (!Set a, !Set a) | < a
/** /**
* Performs a 'split' but also returns whether the pivot element was found in * Performs a 'split' but also returns whether the pivot element was found in
* the original set. * the original set.
*/ */
splitMember :: !a !(Set a) -> (!Set a, !Bool, !Set a) | < a & == a splitMember :: !a !(Set a) -> (!Set a, !Bool, !Set a) | < a
/** /**
* O(n) Post-order fold. * O(n) Post-order fold.
...@@ -228,7 +228,7 @@ toAscList t :== fold (\a as -> [a:as]) [] t ...@@ -228,7 +228,7 @@ toAscList t :== fold (\a as -> [a:as]) [] t
/** /**
* Create a set from a list of elements. * Create a set from a list of elements.
*/ */
fromList :: ![a] -> Set a | < a & == a fromList :: ![a] -> Set a | < a
/** /**
* Map a function to all elements in a set. * Map a function to all elements in a set.
......
...@@ -53,7 +53,7 @@ instance < (Set a) | < a where ...@@ -53,7 +53,7 @@ instance < (Set a) | < a where
//size (Bin sz _ _ _) = sz //size (Bin sz _ _ _) = sz
// | /O(log n)/. Is the element in the set? // | /O(log n)/. Is the element in the set?
member :: !a !(Set a) -> Bool | < a & == a member :: !a !(Set a) -> Bool | < a
member x Tip = False member x Tip = False
member x (Bin _ y l r) member x (Bin _ y l r)
| x < y = member x l | x < y = member x l
...@@ -83,14 +83,14 @@ singleton x = Bin 1 x Tip Tip ...@@ -83,14 +83,14 @@ singleton x = Bin 1 x Tip Tip
// | /O(log n)/. Insert an element in a set. // | /O(log n)/. Insert an element in a set.
// If the set already contains an element equal to the given value, // If the set already contains an element equal to the given value,
// it is replaced with the new value. // it is replaced with the new value.
insert :: !a !.(Set a) -> Set a | < a & == a insert :: !a !.(Set a) -> Set a | < a
insert x Tip = singleton x insert x Tip = singleton x
insert x (Bin sz y l r) insert x (Bin sz y l r)
| x < y = balanceL y (insert x l) r | x < y = balanceL y (insert x l) r
| x > y = balanceR y l (insert x r) | x > y = balanceR y l (insert x r)
| otherwise = Bin sz x l r | otherwise = Bin sz x l r
insertR :: !a !(Set a) -> Set a | < a & == a insertR :: !a !(Set a) -> Set a | < a
insertR x Tip = singleton x insertR x Tip = singleton x
insertR x t=:(Bin _ y l r) insertR x t=:(Bin _ y l r)
| x < y = balanceL y (insertR x l) r | x < y = balanceL y (insertR x l) r
...@@ -98,7 +98,7 @@ insertR x t=:(Bin _ y l r) ...@@ -98,7 +98,7 @@ insertR x t=:(Bin _ y l r)
| otherwise = t | otherwise = t
// | /O(log n)/. Delete an element from a set. // | /O(log n)/. Delete an element from a set.
delete :: !a !.(Set a) -> Set a | < a & == a delete :: !a !.(Set a) -> Set a | < a
delete x Tip = Tip delete x Tip = Tip
delete x (Bin _ y l r) delete x (Bin _ y l r)
| x < y = balanceR y (delete x l) r | x < y = balanceR y (delete x l) r
...@@ -118,7 +118,7 @@ delete x (Bin _ y l r) ...@@ -118,7 +118,7 @@ delete x (Bin _ y l r)
//isSubsetOf :: !(Set a) !(Set a) -> Bool | < a & == a //isSubsetOf :: !(Set a) !(Set a) -> Bool | < a & == a
//isSubsetOf t1 t2 = (size t1 <= size t2) && (isSubsetOfX t1 t2) //isSubsetOf t1 t2 = (size t1 <= size t2) && (isSubsetOfX t1 t2)
isSubsetOfX :: !(Set a) !(Set a) -> Bool | < a & == a isSubsetOfX :: !(Set a) !(Set a) -> Bool | < a
isSubsetOfX Tip _ = True isSubsetOfX Tip _ = True
isSubsetOfX _ Tip = False isSubsetOfX _ Tip = False
isSubsetOfX (Bin _ x l r) t isSubsetOfX (Bin _ x l r) t
...@@ -238,7 +238,7 @@ hedgeInt blo bhi (Bin _ x l r) t2 ...@@ -238,7 +238,7 @@ hedgeInt blo bhi (Bin _ x l r) t2
*--------------------------------------------------------------------*/ *--------------------------------------------------------------------*/
// | /O(n)/. Filter all elements that satisfy the predicate. // | /O(n)/. Filter all elements that satisfy the predicate.
filter :: !(a -> Bool) !(Set a) -> Set a | < a & == a filter :: !(a -> Bool) !(Set a) -> Set a | < a
filter _ Tip = Tip filter _ Tip = Tip
filter p (Bin _ x l r) filter p (Bin _ x l r)
| p x = link x (filter p l) (filter p r) | p x = link x (filter p l) (filter p r)
...@@ -247,7 +247,7 @@ filter p (Bin _ x l r) ...@@ -247,7 +247,7 @@ filter p (Bin _ x l r)
// | /O(n)/. Partition the set into two sets, one with all elements that satisfy // | /O(n)/. Partition the set into two sets, one with all elements that satisfy
// the predicate and one with all elements that don't satisfy the predicate. // the predicate and one with all elements that don't satisfy the predicate.
// See also 'split'. // See also 'split'.
partition :: !(a -> Bool) !(Set a) -> (!Set a, !Set a) | < a & == a partition :: !(a -> Bool) !(Set a) -> (!Set a, !Set a) | < a
partition _ Tip = (Tip,Tip) partition _ Tip = (Tip,Tip)
partition p (Bin _ x l r) partition p (Bin _ x l r)
#! (l1,l2) = partition p l #! (l1,l2) = partition p l
...@@ -277,10 +277,10 @@ fold f z (Bin _ x l r) = fold f (f x (fold f z r)) l ...@@ -277,10 +277,10 @@ fold f z (Bin _ x l r) = fold f (f x (fold f z r)) l
//toAscList t = fold (\a as -> [a:as]) [] t //toAscList t = fold (\a as -> [a:as]) [] t
// | /O(n*log n)/. Create a set from a list of elements. // | /O(n*log n)/. Create a set from a list of elements.
fromList :: ![a] -> Set a | < a & == a fromList :: ![a] -> Set a | < a
fromList xs = foldl ins newSet xs fromList xs = foldl ins newSet xs
where where
ins :: !(Set a) !a -> Set a | < a & == a ins :: !(Set a) !a -> Set a | < a
ins t x = insert x t ins t x = insert x t
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -354,7 +354,7 @@ filterLt (JustS b) t = filter` b t ...@@ -354,7 +354,7 @@ filterLt (JustS b) t = filter` b t
// | /O(log n)/. The expression (@'split' x set@) is a pair @(set1,set2)@ // | /O(log n)/. The expression (@'split' x set@) is a pair @(set1,set2)@
// where @set1@ comprises the elements of @set@ less than @x@ and @set2@ // where @set1@ comprises the elements of @set@ less than @x@ and @set2@
// comprises the elements of @set@ greater than @x@. // comprises the elements of @set@ greater than @x@.
split :: !a !(Set a) -> (!Set a, !Set a) | < a & == a split :: !a !(Set a) -> (!Set a, !Set a) | < a
split _ Tip = (Tip,Tip) split _ Tip = (Tip,Tip)
split x (Bin _ y l r) split x (Bin _ y l r)
| x < y | x < y
...@@ -367,7 +367,7 @@ split x (Bin _ y l r) ...@@ -367,7 +367,7 @@ split x (Bin _ y l r)
// | /O(log n)/. Performs a 'split' but also returns whether the pivot // | /O(log n)/. Performs a 'split' but also returns whether the pivot
// element was found in the original set. // element was found in the original set.
splitMember :: !a !(Set a) -> (!Set a, !Bool, !Set a) | < a & == a splitMember :: !a !(Set a) -> (!Set a, !Bool, !Set a) | < a
splitMember _ Tip = (Tip, False, Tip) splitMember _ Tip = (Tip, False, Tip)
splitMember x (Bin _ y l r) splitMember x (Bin _ y l r)
| x < y | x < y
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment