module Math.ExpPairs.Process
( Process ()
, Path (Path)
, aPath
, baPath
, evalPath
, lengthPath
) where
import GHC.Generics (Generic)
import Data.Monoid
import Text.PrettyPrint.Leijen hiding ((<>))
import Math.ExpPairs.ProcessMatrix
import Math.ExpPairs.PrettyProcess
data Path = Path !ProcessMatrix ![Process]
deriving (Eq, Show, Generic)
instance Monoid Path where
mempty = Path mempty mempty
mappend (Path m1 p1) (Path m2 p2) = Path (m1 <> m2) (p1 <> p2)
instance Pretty Path where
pretty (Path _ l) = pretty (prettify l)
instance Read Path where
readsPrec _ zs = [reads' zs] where
reads' ('A':xs) = (aPath <> path, ys) where
(path, ys) = reads' xs
reads' ('B':'A':xs) = (baPath <> path, ys) where
(path, ys) = reads' xs
reads' ('B':xs) = (baPath, xs)
reads' xs = (mempty, xs)
instance Ord Path where
(Path _ q1) <= (Path _ q2) = cmp q1 q2 where
cmp (A:p1) (A:p2) = cmp p1 p2
cmp (BA:p1) (BA:p2) = cmp p2 p1
cmp (A:_) (BA:_) = True
cmp (BA:_) (A:_) = False
cmp [] _ = True
cmp _ [] = False
aPath :: Path
aPath = Path aMatrix [ A]
baPath :: Path
baPath = Path baMatrix [BA]
evalPath :: (Num t) => Path -> (t, t, t) -> (t, t, t)
evalPath (Path m _) = evalMatrix m
lengthPath :: Path -> Int
lengthPath (Path _ xs) = length xs