From 2241bf9d20ca4c1c186ae945e4a8f8a84146ad24 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 27 Dec 2020 22:46:49 +0100 Subject: [PATCH] Start the library with the idea of a solution from Alex Knauth. --- main.rkt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 main.rkt diff --git a/main.rkt b/main.rkt new file mode 100644 index 0000000..1f33ae2 --- /dev/null +++ b/main.rkt @@ -0,0 +1,32 @@ +#lang typed/racket + +;https://stackoverflow.com/questions/65386334/racket-generic-graph-library-in-typed-racket + +(module graph-wrapper racket + (require (prefix-in g: graph)) + (provide graph? + directed-graph + has-edge? + graphviz) + + (struct graph (g)) + + (define (directed-graph es [ws #f]) + (graph (g:directed-graph es ws))) + (define (has-edge? g u v) + (g:has-edge? (graph-g g) u v)) + (define (graphviz g #:output [output #f] #:colors [colors #f]) + (g:graphviz (graph-g g) #:output output #:colors colors))) + +(require/typed 'graph-wrapper + [#:opaque Graph graph?] + [directed-graph (->* ((Listof (List Any Any))) ((Listof Any)) Graph)] + [has-edge? (-> Graph Any Any Boolean)] + [graphviz (->* (Graph) + (#:output Output-Port + #:colors (HashTable Any Natural)) + String)]) + +(define g (directed-graph '((a b) (b c)))) +(has-edge? g 'a 'c) +(graphviz g)