Skip to content

Commit d28b47d

Browse files
epostmarcosh
authored andcommitted
[#328] [stbx-core] Use Tokens instead of Int and mark copied types.
1 parent d39eae9 commit d28b47d

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

Diff for: stbx-core/src/Statebox/Core/Transition.purs

+24-15
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,38 @@ import Data.ArrayMultiset (ArrayMultiset)
1111
import Statebox.Core.Execution (Path)
1212
import Statebox.Core.Types (PID, TID)
1313

14-
-- TODO: these types are currently duplicated from Data.Petrinet.Representation.Dict
14+
--------------------------------------------------------------------------------
15+
16+
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
1517
type TransitionF p tok =
1618
{ pre :: Array (PlaceMarkingF p tok)
1719
, post :: Array (PlaceMarkingF p tok)
1820
}
1921

22+
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
2023
type PlaceMarkingF p tok =
2124
{ place :: p
2225
, tokens :: tok
2326
}
2427

25-
buildTokens :: a. Ord a => ArrayMultiset a -> ArrayMultiset a -> TransitionF a Int
28+
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
29+
type Tokens = Int
30+
31+
--------------------------------------------------------------------------------
32+
33+
buildTokens :: a. Ord a => ArrayMultiset a -> ArrayMultiset a -> TransitionF a Tokens
2634
buildTokens pre post =
27-
{ pre : buildPlaceMarkings pre
28-
, post : buildPlaceMarkings post
35+
{ pre: buildPlaceMarkings pre
36+
, post: buildPlaceMarkings post
2937
}
3038

31-
buildPlaceMarkings :: a. Ord a => ArrayMultiset a -> Array (PlaceMarkingF a Int)
32-
buildPlaceMarkings multiset =
33-
let map = foldr (Map.update (Just <<< (_ + 1))) Map.empty multiset
34-
in foldrWithIndex (\place count -> (:) { place: place, tokens: count }) [] map
39+
buildPlaceMarkings :: a. Ord a => ArrayMultiset a -> Array (PlaceMarkingF a Tokens)
40+
buildPlaceMarkings netMarking =
41+
foldrWithIndex (\place tokens -> (:) { place, tokens }) [] netMarkingDict
42+
where
43+
netMarkingDict = netMarking # foldr (Map.update (Just <<< (_ + 1))) mempty
3544

36-
type Tokens = Int
45+
--------------------------------------------------------------------------------
3746

3847
type Transition =
3948
{ path :: Path
@@ -60,9 +69,9 @@ isFinal = case _ of
6069

6170
gluedTokens :: Glued Transition -> TransitionF PID Tokens
6271
gluedTokens = case _ of
63-
Untouched transition -> transition.tokens
64-
Initial transition -> transition.tokens
65-
Final transition -> transition.tokens
66-
Glued transition1 transition2 -> { pre : transition1.tokens.pre
67-
, post: transition2.tokens.post
68-
}
72+
Untouched transition -> transition.tokens
73+
Initial transition -> transition.tokens
74+
Final transition -> transition.tokens
75+
Glued transition1 transition2 -> { pre: transition1.tokens.pre
76+
, post: transition2.tokens.post
77+
}

0 commit comments

Comments
 (0)