Skip to content
Snippets Groups Projects
Commit 3bcf720a authored by Jens Nolte's avatar Jens Nolte
Browse files

Remove redundant constraints

parent 36dc2211
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ leftToMaybe (Left x) = Just x
leftToMaybe (Right _) = Nothing
-- | Returns all duplicate elements in a list. The order of the produced list is unspecified.
duplicates :: forall a. (Eq a, Hashable.Hashable a) => [a] -> [a]
duplicates :: forall a. Hashable.Hashable a => [a] -> [a]
duplicates = HS.toList . duplicates' HS.empty
where
duplicates' :: HS.HashSet a -> [a] -> HS.HashSet a
......@@ -77,14 +77,14 @@ duplicates = HS.toList . duplicates' HS.empty
otherDuplicates = duplicates' (HS.insert x set) xs
-- | Lookup and delete a value from a HashMap in one operation
lookupDelete :: forall k v. (Eq k, Hashable.Hashable k) => k -> HM.HashMap k v -> (Maybe v, HM.HashMap k v)
lookupDelete :: forall k v. Hashable.Hashable k => k -> HM.HashMap k v -> (Maybe v, HM.HashMap k v)
lookupDelete key m = swap $ State.runState fn Nothing
where
fn :: State.State (Maybe v) (HM.HashMap k v)
fn = HM.alterF (\c -> State.put c >> return Nothing) key m
-- | Lookup a value and insert the given value if it is not already a member of the HashMap.
lookupInsert :: forall k v. (Eq k, Hashable.Hashable k) => k -> v -> HM.HashMap k v -> (v, HM.HashMap k v)
lookupInsert :: forall k v. Hashable.Hashable k => k -> v -> HM.HashMap k v -> (v, HM.HashMap k v)
lookupInsert key value hm = runExtra $ HM.alterF fn key hm
where
fn :: Maybe v -> Extra v (Maybe v)
......@@ -92,7 +92,7 @@ lookupInsert key value hm = runExtra $ HM.alterF fn key hm
fn (Just oldValue) = Extra (oldValue, Just oldValue)
-- | Insert the given value if it is not already a member of the HashMap. Returns `True` if the element was inserted.
checkInsert :: forall k v. (Eq k, Hashable.Hashable k) => k -> v -> HM.HashMap k v -> (Bool, HM.HashMap k v)
checkInsert :: forall k v. Hashable.Hashable k => k -> v -> HM.HashMap k v -> (Bool, HM.HashMap k v)
checkInsert key value hm = runExtra $ HM.alterF fn key hm
where
fn :: Maybe v -> Extra Bool (Maybe v)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment