Skip to content

Commit 5532fcf

Browse files
committed
Support containers < 0.4.2 again
Duplicate the intent of IM.foldlWithKey' (which was added in 0.4.2) with foldWithKey. Closes #69
1 parent 032b779 commit 5532fcf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Data/Graph/Inductive/PatriciaTree.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ addLists xs ys = xs ++ ys
273273

274274
addSucc :: forall a b . GraphRep a b -> Node -> Int -> IM.IntMap [b] -> GraphRep a b
275275
addSucc g0 v numAdd xs
276-
| numAdd < bulkThreshold = IM.foldlWithKey' go g0 xs
276+
| numAdd < bulkThreshold = foldlWithKey' go g0 xs
277277
where
278278
go :: GraphRep a b -> Node -> [b] -> GraphRep a b
279279
go g p l = IMS.adjust f p g
@@ -285,9 +285,19 @@ addSucc g v _ xs = IMS.differenceWith go g xs
285285
go (ps, l', ss) l = let !ss' = IM.insertWith addLists v l ss
286286
in Just (ps, l', ss')
287287

288+
foldlWithKey' :: (a -> IM.Key -> b -> a) -> a -> IntMap b -> a
289+
foldlWithKey' =
290+
#if MIN_VERSION_containers (0,4,2)
291+
IM.foldlWithKey'
292+
#else
293+
IM.foldWithKey . adjustFunc
294+
where
295+
adjustFunc f k b a = f a k b
296+
#endif
297+
288298
addPred :: forall a b . GraphRep a b -> Node -> Int -> IM.IntMap [b] -> GraphRep a b
289299
addPred g0 v numAdd xs
290-
| numAdd < bulkThreshold = IM.foldlWithKey' go g0 xs
300+
| numAdd < bulkThreshold = foldlWithKey' go g0 xs
291301
where
292302
go :: GraphRep a b -> Node -> [b] -> GraphRep a b
293303
go g p l = IMS.adjust f p g

0 commit comments

Comments
 (0)