         }
     }
 }
+
+
+/// Helper function used when generating DOT digraph strings.
+private func label<T: DOTLabel>(x: T) -> String {
+    return x.DOTLabel
+}

    }

    private static func DOTDigraphGivenTransitionLogic(transitionLogic: (State, Event) -> (State, (Subject -> ())?)?, initialState: State, states: [State], events: [Event]) -> String {
        let stateIndexesByLabel: [String: Int] = {
            var d: [String: Int] = [:]

            for (i, state) in enumerate(states) {
                d[state.DOTLabel] = i + 1
            }

            return d
        }()

        var digraph = "digraph {\n    graph [rankdir=LR]\n\n    0 [label=\"\", shape=plaintext]\n    0 -> \(stateIndexesByLabel[initialState.DOTLabel]!) [label=\"START\"]\n\n"

        for state in states {
            let label = state.DOTLabel
            digraph += "    \(stateIndexesByLabel[label]!) [label=\"\(label)\"]\n"
        }

        digraph += "\n"

        for fromState in states {
            for event in events {
                if let (toState, _) = transitionLogic(fromState, event) {
                    digraph += "    \(index(fromState)) -> \(index(toState)) [label=\"\(label(event))\"]\n"
                }
            }
        }
