File talk:Combinatorial species generic structure.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Source code[edit]

The source code is written in Haskell, using the diagrams framework.

{-# LANGUAGE NoMonomorphismRestriction #-}

import           Data.Colour.Palette.ColorSet
import           Diagrams.Backend.Cairo.CmdLine
import           Diagrams.Prelude

blue' = d3Colors1 0
red' = d3Colors1 3
lblue' = d3Colors1 9

elt c n = circle 1 # fc c # lw 0 # named n

mkSet' es c n = vcat' (with & sep .~ 1) elts # centerY # enbox 0.5 c
  where
    elts = zipWith (\e n -> e c n) es [0::Int .. ]

mkSet c n = mkSet' (replicate n elt) c n

enbox off c d = r <> d'
  where
    d' = d # frame off
    r  = boundingRect d' # dashing [0.2,0.2] 0 # lc c # lw 0.1


genericStruct = hcat' (with & sep .~ 6)
  [ elt red' "root"
  , mkSet blue' 5
  ]
  # applyAll (map (conn red' "root") [0::Int .. 5])

conn :: (IsName n1, IsName n2) => Colour Double -> n1 -> n2 -> Diagram B R2 -> Diagram B R2
conn c  = connectOutside' (with & shaftStyle %~ lw 0.1 . lc c & arrowHead .~ noHead)

main = defaultMain (genericStruct # frame 0.5)