@@ -4,6 +4,7 @@ import Prelude
4
4
import Control.Apply (lift3 )
5
5
import Data.Array (head , length , partition , range )
6
6
import Data.Either (Either (..), either )
7
+ import Data.Either.Nested (type (\/))
7
8
import Data.Maybe (Maybe )
8
9
import Data.Tuple.Nested ((/\))
9
10
@@ -16,10 +17,10 @@ data WiringTree
16
17
= Net Net
17
18
| Diagram Diagram (Array WiringTree )
18
19
19
- -- | This function translates a `Wiring` into a `WiringTree`
20
- -- | For the moment, we forget about diagrams and gluings and we consider only simple nets
21
- wiringToWiringTree :: Wiring -> Maybe WiringTree
22
- wiringToWiringTree wiring = Net <$> head wiring.nets
20
+ -- | This function translates a `Wiring` into a `WiringTree`.
21
+ -- | For the moment, we forget about diagrams and gluings and we consider only simple nets.
22
+ fromWiring :: Wiring -> Maybe WiringTree
23
+ fromWiring wiring = Net <$> head wiring.nets
23
24
24
25
type Transition =
25
26
{ path :: Path
@@ -33,34 +34,34 @@ data Glued a
33
34
| Final a
34
35
| Glued a a
35
36
36
- isInitial :: forall a . Glued a -> Boolean
37
+ isInitial :: ∀ a . Glued a -> Boolean
37
38
isInitial = case _ of
38
39
Initial a -> true
39
40
_ -> false
40
41
41
- isFinal :: forall a . Glued a -> Boolean
42
+ isFinal :: ∀ a . Glued a -> Boolean
42
43
isFinal = case _ of
43
44
Final a -> true
44
45
_ -> false
45
46
46
- data LinerisationError
47
+ data LinearizationError
47
48
= DiagramNotYetAllowed
48
49
| NLLDecodingFailed ErrNetEncoding
49
50
50
- linearise :: WiringTree -> Either LinerisationError ( Array (Glued Transition ) )
51
- linearise (Net net) = lineariseNet net
52
- linearise (Diagram diagram branches) = Left DiagramNotYetAllowed
51
+ linearize :: WiringTree -> LinearizationError \/ Array (Glued Transition )
52
+ linearize (Net net) = linearizeNet net
53
+ linearize (Diagram diagram branches) = Left DiagramNotYetAllowed
53
54
54
- lineariseNet :: Net -> Either LinerisationError ( Array (Glued Transition ) )
55
- lineariseNet net = linearisePartitionsAndNames net.partition net.names
55
+ linearizeNet :: Net -> LinearizationError \/ Array (Glued Transition )
56
+ linearizeNet net = linearizePartitionsAndNames net.partition net.names
56
57
57
- linearisePartitionsAndNames :: ArrayMultiset PID -> Array String -> Either LinerisationError ( Array (Glued Transition ) )
58
- linearisePartitionsAndNames partition names =
59
- either (NLLDecodingFailed >>> Left ) (Right <<< flip lineriseTransitionsAndNames names) $ fromNLL 0 partition
58
+ linearizePartitionsAndNames :: ArrayMultiset PID -> Array String -> LinearizationError \/ Array (Glued Transition )
59
+ linearizePartitionsAndNames partition names =
60
+ either (NLLDecodingFailed >>> Left ) (Right <<< flip linearizeTransitionsAndNames names) $ fromNLL 0 partition
60
61
61
- -- the use of `lift3` does not consider the fact that the arrays could in principle have different lenghts
62
- lineriseTransitionsAndNames :: Array (TransitionF' PID ) -> Array String -> Array (Glued Transition )
63
- lineriseTransitionsAndNames transitions names =
62
+ -- the use of `lift3` does not consider the fact that the arrays could in principle have different lengths
63
+ linearizeTransitionsAndNames :: Array (TransitionF' PID ) -> Array String -> Array (Glued Transition )
64
+ linearizeTransitionsAndNames transitions names =
64
65
sortInitialFinal $ lift3 buildGluedTransition (range 0 (length transitions - 1 )) transitions names
65
66
66
67
buildGluedTransition :: TID -> TransitionF' PID -> String -> Glued Transition
@@ -70,9 +71,9 @@ buildGluedTransition tId (inputs /\ outputs) name =
70
71
(_ /\ [] ) -> Final { name: name, path: [0 , 0 , 0 ], transition: tId }
71
72
(inp /\ out) -> Untouched { name: name, path: [0 , 0 , 0 ], transition: tId }
72
73
73
- -- | we are using this custom function instead of `sortBy` because that does not guarantee
74
- -- | the order of equal things to be preserved
75
- sortInitialFinal :: forall a . Array (Glued a ) -> Array (Glued a )
74
+ -- | We use this custom function instead of `sortBy` because that does not guarantee
75
+ -- | the order of equal elements to be preserved.
76
+ sortInitialFinal :: ∀ a . Array (Glued a ) -> Array (Glued a )
76
77
sortInitialFinal gluedItems =
77
78
let { no: notInitial , yes: initial } = partition isInitial gluedItems
78
79
{ no: notInitialAndFinal, yes: final } = partition isFinal notInitial
0 commit comments