Skip to content

Commit 0e089a9

Browse files
committed
Add Bifunctor instances
Only valid for base >= 4.8.0.0. Closes #33
1 parent fe106af commit 0e089a9

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Data/Graph/Inductive/PatriciaTree.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module Data.Graph.Inductive.PatriciaTree
2828
import Data.Graph.Inductive.Graph
2929

3030
import Control.Applicative (liftA2)
31-
import Control.Arrow (second)
3231
import Data.IntMap (IntMap)
3332
import qualified Data.IntMap as IM
3433
import Data.List (sort)
@@ -42,6 +41,12 @@ import Control.DeepSeq (NFData (..))
4241
import GHC.Generics (Generic)
4342
#endif
4443

44+
#if MIN_VERSION_base (4,8,0)
45+
import Data.Bifunctor
46+
#else
47+
import Control.Arrow (second)
48+
#endif
49+
4550
----------------------------------------------------------------------
4651
-- GRAPH REPRESENTATION
4752
----------------------------------------------------------------------
@@ -120,6 +125,15 @@ instance (NFData a, NFData b) => NFData (Gr a b) where
120125
rnf (Gr g) = rnf g
121126
#endif
122127

128+
#if MIN_VERSION_base (4,8,0)
129+
instance Bifunctor Gr where
130+
bimap = fastNEMap
131+
132+
first = fastNMap
133+
134+
second = fastEMap
135+
#endif
136+
123137
matchGr :: Node -> Gr a b -> Decomp Gr a b
124138
matchGr node (Gr g)
125139
= case IM.lookup node g of

Data/Graph/Inductive/Tree.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module Data.Graph.Inductive.Tree (Gr,UGr) where
1414
import Data.Graph.Inductive.Graph
1515

1616
import Control.Applicative (liftA2)
17-
import Control.Arrow (first, second)
1817
import Data.List (foldl', sort)
1918
import Data.Map (Map)
2019
import qualified Data.Map as M
@@ -28,6 +27,12 @@ import Control.DeepSeq (NFData (..))
2827
import GHC.Generics (Generic)
2928
#endif
3029

30+
#if MIN_VERSION_base (4,8,0)
31+
import Data.Bifunctor
32+
#else
33+
import Control.Arrow (first, second)
34+
#endif
35+
3136
----------------------------------------------------------------------
3237
-- GRAPH REPRESENTATION
3338
----------------------------------------------------------------------
@@ -130,6 +135,15 @@ instance (NFData a, NFData b) => NFData (Gr a b) where
130135
rnf (Gr g) = rnf g
131136
#endif
132137

138+
#if MIN_VERSION_base (4,8,0)
139+
instance Bifunctor Gr where
140+
bimap = nemap
141+
142+
first = nmap
143+
144+
second = emap
145+
#endif
146+
133147
----------------------------------------------------------------------
134148
-- UTILITIES
135149
----------------------------------------------------------------------

0 commit comments

Comments
 (0)