Skip to content

Instantly share code, notes, and snippets.

@TikhonJelvis
Last active September 22, 2016 06:05
Show Gist options
  • Save TikhonJelvis/11272905 to your computer and use it in GitHub Desktop.
Save TikhonJelvis/11272905 to your computer and use it in GitHub Desktop.
Generating graphs for my Quora answer
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
import qualified Data.Graph.Inductive as Graph
import Data.Graph.Inductive (Gr, match, matchAny)
import Data.String.Interpolation (str)
complex :: Gr () ()
complex = Graph.mkGraph nodes edges
where nodes = [(x, ()) | x <- [1..10]]
edges = [(x, y, ()) | x <- [1..10], y <- [1..10], x < y]
modular :: Gr () ()
modular = Graph.mkGraph nodes edges
where nodes = [(x, ()) | x <- [1..10]]
edges = [(x, y, ()) | x <- [1..10], y <- [1..10], x < y, same x y]
same a b = (a < 6) == (b < 6)
unlabeled graph = [str|
digraph fgl {
margin = "0"
page = "6"
size = "6"
ratio = "fill"
#node in Graph.nodes graph:$:node$|
#
#(a, b, l) in Graph.labEdges graph:$:a$ -> $:b$ [arrowhead = none]|
#
}
|]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment