You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
;;; Copyright 2021 Sergiu Ivanov <sivanov@colimite.fr>


;;;


;;; Licensed under the Apache License, Version 2.0 (the "License");


;;; you may not use this file except in compliance with the License.


;;; You may obtain a copy of the License at


;;;


;;; http://www.apache.org/licenses/LICENSE2.0


;;;


;;; Unless required by applicable law or agreed to in writing, software


;;; distributed under the License is distributed on an "AS IS" BASIS,


;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.


;;; See the License for the specific language governing permissions and


;;; limitations under the License.




#lang typed/racket




;;; This file implements Alex Knauth's solution presented here:


;;;


;;; https://stackoverflow.com/questions/65386334/racketgenericgraphlibraryintypedracket




(module graphwrapper racket


(require (prefixin g: graph))


(provide graph?


directedgraph


hasvertex?


hasedge?


graphviz)




(struct graph (g))




(define (directedgraph es [ws #f])


(graph (g:directedgraph es ws)))


(define (hasvertex? g v)


(g:hasvertex? (graphg g) v))


(define (hasedge? g u v)


(g:hasedge? (graphg g) u v))


(define (graphviz g #:output [output #f] #:colors [colors #f])


(g:graphviz (graphg g) #:output output #:colors colors)))




(require/typed 'graphwrapper


[#:opaque Graph graph?]


[directedgraph (>* ((Listof (List Any Any))) ((Listof Any)) Graph)]


[hasvertex? (> Graph Any Boolean)]


[hasedge? (> Graph Any Any Boolean)]


[graphviz (>* (Graph)


(#:output OutputPort


#:colors (HashTable Any Natural))


String)])




(define g (directedgraph '((a b) (b c))))


(hasedge? g 'a 'c)


(hasvertex? g 'a)


(graphviz g)
