FiniteCategories-0.1.0.0: test/ExampleCompositionGraph/ExampleCompositionGraph.hs
{-| Module : FiniteCategories
Description : An example of composition graph.
Copyright : Guillaume Sabbagh 2021
License : GPL-3
Maintainer : guillaumesabbagh@protonmail.com
Stability : experimental
Portability : portable
An example of composition graph.
-}
module ExampleCompositionGraph.ExampleCompositionGraph
(
square, main
)
where
import CompositionGraph.CompositionGraph
import ExportGraphViz.ExportGraphViz (catToPdf)
import qualified FiniteCategory.FiniteCategory as FinCat (FiniteCategoryError(..))
import Data.Text (Text, pack)
f = (0, 1, pack "f") :: Arrow Int Text
g = (1, 2, pack "g") :: Arrow Int Text
h = (0, 3, pack "h") :: Arrow Int Text
i = (3, 2, pack "i") :: Arrow Int Text
-- | A composition law defined by hand.
myLaw = [([g,f],[i,h])]
myGraph = ([0, 1, 2, 3], [f,g,h,i])
-- | An example of a composition graph
Right square = mkCompositionGraph myGraph myLaw
my_sub_graph = ([0, 1, 3], [f,g,h,i])
-- | A composition subgraph of the previous composition graph.
csg = mkCompositionGraph my_sub_graph myLaw
-- | Exports the composition graphs as pdf files with GraphViz.
main = main_ square csg where
main_ _ (Left err) = putStrLn.show $ err
main_ square (Right csg) = do
putStrLn "Start of ExampleCompositionGraph"
catToPdf square "OutputGraphViz/Examples/CompositionGraph/CompositionGraph/compositionGraph"
catToPdf csg "OutputGraphViz/Examples/CompositionGraph/CompositionGraph/compositionGraph2"
putStrLn "End of ExampleCompositionGraph"