{-| Module : FiniteCategories Description : An example of safe composition graph. Copyright : Guillaume Sabbagh 2021 License : GPL-3 Maintainer : guillaumesabbagh@protonmail.com Stability : experimental Portability : portable An example of safe composition graph. -} module ExampleCompositionGraph.ExampleSafeCompositionGraph ( squareS, main ) where import CompositionGraph.CompositionGraph import CompositionGraph.SafeCompositionGraph 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 j = (3, 3, pack "j") :: Arrow Int Text -- | A composition law defined by hand. myLaw = [([g,f],[i,h])] myGraph = ([0, 1, 2, 3], [f,g,h,i,j]) -- | An example of a composition graph squareS = mkSafeCompositionGraph myGraph myLaw 3 my_sub_graph = ([0, 1, 2], [f,j]) -- | A composition subgraph of the previous composition graph. csg = mkSafeCompositionGraph my_sub_graph myLaw 2 -- | Exports the composition graphs as pdf files with GraphViz. main = main_ squareS csg where main_ (Left err) _ = putStrLn.show $ err main_ _ (Left err) = putStrLn.show $ err main_ (Right squareS) (Right csg) = do putStrLn "Start of ExampleSafeCompositionGraph" catToPdf squareS "OutputGraphViz/Examples/CompositionGraph/SafeCompositionGraph/compositionGraph" catToPdf csg "OutputGraphViz/Examples/CompositionGraph/SafeCompositionGraph/compositionGraph2" putStrLn "End of ExampleSafeCompositionGraph"