Skip to content

Commit

Permalink
[#328] [stbx-core] Fix typos and standardise spelling and naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
epost committed Jan 31, 2020
1 parent 19f5f06 commit 51ff7ac
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions stbx-core/src/Statebox/Core/WiringTree.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Prelude
import Control.Apply (lift3)
import Data.Array (head, length, partition, range)
import Data.Either (Either(..), either)
import Data.Either.Nested (type (\/))
import Data.Maybe (Maybe)
import Data.Tuple.Nested ((/\))

Expand All @@ -16,10 +17,10 @@ data WiringTree
= Net Net
| Diagram Diagram (Array WiringTree)

-- | This function translates a `Wiring` into a `WiringTree`
-- | For the moment, we forget about diagrams and gluings and we consider only simple nets
wiringToWiringTree :: Wiring -> Maybe WiringTree
wiringToWiringTree wiring = Net <$> head wiring.nets
-- | This function translates a `Wiring` into a `WiringTree`.
-- | For the moment, we forget about diagrams and gluings and we consider only simple nets.
fromWiring :: Wiring -> Maybe WiringTree
fromWiring wiring = Net <$> head wiring.nets

type Transition =
{ path :: Path
Expand All @@ -33,34 +34,34 @@ data Glued a
| Final a
| Glued a a

isInitial :: forall a. Glued a -> Boolean
isInitial :: a. Glued a -> Boolean
isInitial = case _ of
Initial a -> true
_ -> false

isFinal :: forall a. Glued a -> Boolean
isFinal :: a. Glued a -> Boolean
isFinal = case _ of
Final a -> true
_ -> false

data LinerisationError
data LinearizationError
= DiagramNotYetAllowed
| NLLDecodingFailed ErrNetEncoding

linearise :: WiringTree -> Either LinerisationError (Array (Glued Transition))
linearise (Net net) = lineariseNet net
linearise (Diagram diagram branches) = Left DiagramNotYetAllowed
linearize :: WiringTree -> LinearizationError \/ Array (Glued Transition)
linearize (Net net) = linearizeNet net
linearize (Diagram diagram branches) = Left DiagramNotYetAllowed

lineariseNet :: Net -> Either LinerisationError (Array (Glued Transition))
lineariseNet net = linearisePartitionsAndNames net.partition net.names
linearizeNet :: Net -> LinearizationError \/ Array (Glued Transition)
linearizeNet net = linearizePartitionsAndNames net.partition net.names

linearisePartitionsAndNames :: ArrayMultiset PID -> Array String -> Either LinerisationError (Array (Glued Transition))
linearisePartitionsAndNames partition names =
either (NLLDecodingFailed >>> Left) (Right <<< flip lineriseTransitionsAndNames names) $ fromNLL 0 partition
linearizePartitionsAndNames :: ArrayMultiset PID -> Array String -> LinearizationError \/ Array (Glued Transition)
linearizePartitionsAndNames partition names =
either (NLLDecodingFailed >>> Left) (Right <<< flip linearizeTransitionsAndNames names) $ fromNLL 0 partition

-- the use of `lift3` does not consider the fact that the arrays could in principle have different lenghts
lineriseTransitionsAndNames :: Array (TransitionF' PID) -> Array String -> Array (Glued Transition)
lineriseTransitionsAndNames transitions names =
-- the use of `lift3` does not consider the fact that the arrays could in principle have different lengths
linearizeTransitionsAndNames :: Array (TransitionF' PID) -> Array String -> Array (Glued Transition)
linearizeTransitionsAndNames transitions names =
sortInitialFinal $ lift3 buildGluedTransition (range 0 (length transitions - 1)) transitions names

buildGluedTransition :: TID -> TransitionF' PID -> String -> Glued Transition
Expand All @@ -70,9 +71,9 @@ buildGluedTransition tId (inputs /\ outputs) name =
(_ /\ [] ) -> Final { name: name, path: [0, 0, 0], transition: tId }
(inp /\ out) -> Untouched { name: name, path: [0, 0, 0], transition: tId }

-- | we are using this custom function instead of `sortBy` because that does not guarantee
-- | the order of equal things to be preserved
sortInitialFinal :: forall a. Array (Glued a) -> Array (Glued a)
-- | We use this custom function instead of `sortBy` because that does not guarantee
-- | the order of equal elements to be preserved.
sortInitialFinal :: a. Array (Glued a) -> Array (Glued a)
sortInitialFinal gluedItems =
let { no: notInitial , yes: initial } = partition isInitial gluedItems
{ no: notInitialAndFinal, yes: final } = partition isFinal notInitial
Expand Down

0 comments on commit 51ff7ac

Please sign in to comment.