@@ -18,7 +18,7 @@ module Ideas.Common.Strategy.Derived
1818 permute , many , many1 , replicate , option , try
1919 , repeat , repeat1 , exhaustive
2020 -- * Process-specific combinators
21- , atomic , (<%>) , interleave , concurrent
21+ , atomic , (<%>) , interleave
2222 , (<@>) , (!*>) , inits , filterP , hide
2323 ) where
2424
@@ -56,9 +56,11 @@ split2 op1 op2 = withMenu f
5656
5757-- atomic prefix
5858(!*>) :: AtomicSymbol a => Process a -> Process a -> Process a
59- a !*> p = split op (atomic a ) p
59+ a !*> p = atomicOpen ~> a .*. withMenu op (single atomicClose ) p
6060 where
61- op b q = atomic (a .*. b) .*. q
61+ op b q
62+ | b == atomicOpen = q
63+ | otherwise = b ~> atomicClose ~> q
6264
6365filterP :: (a -> Bool ) -> Process a -> Process a
6466filterP cond = fold (\ a q -> if cond a then a ~> q else empty) done
@@ -72,23 +74,28 @@ atomic p = atomicOpen ~> (p .*. single atomicClose)
7274interleave :: (AtomicSymbol a , LabelSymbol a ) => [Process a ] -> Process a
7375interleave xs = if null xs then done else foldr1 (<%>) xs
7476
77+ -- interleaving
7578(<%>) :: (AtomicSymbol a , LabelSymbol a ) => Process a -> Process a -> Process a
76- (<%>) = concurrent (not . isEnterSymbol)
77-
78- concurrent :: AtomicSymbol a => (a -> Bool ) -> Process a -> Process a -> Process a
79- concurrent switch = normal
79+ p <%> q =
80+ bothAreDone p q .|. ((p %>> q) .|. (q %>> p))
8081 where
81- normal p q = stepBoth q p .|. (stepRight q p .|. stepRight p q)
82-
83- stepBoth = withMenu stop2 . withMenu stop2 done
84- stop2 _ _ = empty
82+ bothAreDone = withMenu stop2 . withMenu stop2 done
83+ stop2 _ _ = empty
8584
86- stepRight p = split2 op1 op2 empty
85+ -- left-interleaving
86+ (%>>) :: (AtomicSymbol a , LabelSymbol a ) => Process a -> Process a -> Process a
87+ p %>> q = rec (0 :: Int ) p
88+ where
89+ rec n = withMenu op empty
8790 where
88- op1 a q2
89- | switch a = a ~> normal p q2
90- | otherwise = a ~> stepRight p q2
91- op2 q1 q2 = q1 .*. normal p q2
91+ op a = a ~> rest
92+ where
93+ next | a == atomicOpen = n+ 1
94+ | a == atomicClose = n- 1
95+ | otherwise = n
96+ rest | isEnterSymbol a = rec next
97+ | next > 0 = rec next
98+ | otherwise = (<%> q)
9299
93100-- | Allows all permutations of the list
94101permute :: (Choice a , Sequence a ) => [a ] -> a
0 commit comments