@@ -13,7 +13,6 @@ import Data.HashMap.Mutable.Linear (HashMap)
13
13
import qualified Data.HashMap.Mutable.Linear as HMap
14
14
import Data.Maybe.Linear (catMaybes )
15
15
import Data.Unrestricted.Linear
16
- import Prelude.Linear ((&) )
17
16
import qualified Prelude.Linear as Linear
18
17
19
18
-- # The topological sort of a DAG
@@ -36,7 +35,7 @@ topsort = reverse . postOrder . fmap (\(n, nbrs) -> (n, (nbrs, 0)))
36
35
37
36
postOrderHM :: [Node ] -> InDegGraph % 1 -> Ur [Node ]
38
37
postOrderHM nodes dag =
39
- findSources nodes (computeInDeg nodes dag) & \ case
38
+ case findSources nodes (computeInDeg nodes dag) of
40
39
(dag, Ur sources) -> pluckSources sources [] dag
41
40
where
42
41
-- O(V + N)
@@ -46,7 +45,7 @@ postOrderHM nodes dag =
46
45
-- Increment in-degree of all neighbors
47
46
incChildren :: InDegGraph % 1 -> Ur Node % 1 -> InDegGraph
48
47
incChildren dag (Ur node) =
49
- HMap. lookup node dag & \ case
48
+ case HMap. lookup node dag of
50
49
(Ur Nothing , dag) -> dag
51
50
(Ur (Just (xs, i)), dag) -> incNodes (move xs) dag
52
51
where
@@ -55,7 +54,7 @@ postOrderHM nodes dag =
55
54
56
55
incNode :: InDegGraph % 1 -> Ur Node % 1 -> InDegGraph
57
56
incNode dag (Ur node) =
58
- HMap. lookup node dag & \ case
57
+ case HMap. lookup node dag of
59
58
(Ur Nothing , dag') -> dag'
60
59
(Ur (Just (n, d)), dag') ->
61
60
HMap. insert node (n, d + 1 ) dag'
@@ -66,10 +65,10 @@ postOrderHM nodes dag =
66
65
pluckSources :: [Node ] -> [Node ] -> InDegGraph % 1 -> Ur [Node ]
67
66
pluckSources [] postOrd dag = lseq dag (move postOrd)
68
67
pluckSources (s : ss) postOrd dag =
69
- HMap. lookup s dag & \ case
68
+ case HMap. lookup s dag of
70
69
(Ur Nothing , dag) -> pluckSources ss (s : postOrd) dag
71
70
(Ur (Just (xs, i)), dag) ->
72
- walk xs dag & \ case
71
+ case walk xs dag of
73
72
(dag', Ur newSrcs) ->
74
73
pluckSources (newSrcs ++ ss) (s : postOrd) dag'
75
74
where
@@ -81,7 +80,7 @@ pluckSources (s : ss) postOrd dag =
81
80
-- Decrement the degree of a node, save it if it is now a source
82
81
decDegree :: Node -> InDegGraph % 1 -> (InDegGraph , Ur (Maybe Node ))
83
82
decDegree node dag =
84
- HMap. lookup node dag & \ case
83
+ case HMap. lookup node dag of
85
84
(Ur Nothing , dag') -> (dag', Ur Nothing )
86
85
(Ur (Just (n, d)), dag') ->
87
86
checkSource node (HMap. insert node (n, d - 1 ) dag')
@@ -94,7 +93,7 @@ findSources nodes dag =
94
93
-- | Check if a node is a source, and if so return it
95
94
checkSource :: Node -> InDegGraph % 1 -> (InDegGraph , Ur (Maybe Node ))
96
95
checkSource node dag =
97
- HMap. lookup node dag & \ case
96
+ case HMap. lookup node dag of
98
97
(Ur Nothing , dag) -> (dag, Ur Nothing )
99
98
(Ur (Just (xs, 0 )), dag) -> (dag, Ur (Just node))
100
99
(Ur (Just (xs, n)), dag) -> (dag, Ur Nothing )
@@ -103,5 +102,5 @@ mapAccum ::
103
102
(a -> b % 1 -> (b , Ur c )) -> [a ] -> b % 1 -> (b , Ur [c ])
104
103
mapAccum f [] b = (b, Ur [] )
105
104
mapAccum f (x : xs) b =
106
- mapAccum f xs b & \ case
105
+ case mapAccum f xs b of
107
106
(b, Ur cs) -> second (Data. fmap (: cs)) (f x b)
0 commit comments