From 333a909385ce5b2e6d5965adb62f4935bbf861ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 18 Nov 2015 15:26:55 +0100 Subject: [PATCH] Started writing fold-queues module, which can process multiple queues with distinct types. --- graph/graph/fold-queues.lp2.rkt | 97 +++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 graph/graph/fold-queues.lp2.rkt diff --git a/graph/graph/fold-queues.lp2.rkt b/graph/graph/fold-queues.lp2.rkt new file mode 100644 index 00000000..bddf6ce5 --- /dev/null +++ b/graph/graph/fold-queues.lp2.rkt @@ -0,0 +1,97 @@ +#lang debug scribble/lp2 +@(require "../lib/doc.rkt") +@doc-lib-setup + +@title[#:style manual-doc-style]{The queue library} + +@(table-of-contents) + +@section{Introduction} + +@section{Implementation} + +@chunk[ + (fold-queues root-value + [(name [element (~literal :) element-type] Δ-queues get-tag) + (~literal :) result-type + . body] + ...)] + +@chunk[ + (define/with-syntax get-tag/type + #'(∀ (X) (case→ (→ 'name element-type X (values Index X)) + ...)))] + +@chunk[ + (define/with-syntax queues/type + #'(List (Δ-Hash element-type Index) ...))] + +@chunk[ + (define-syntax/parse + + + #'(list (λ ([element : element-type] + [get-tag : get-tag/type] + [Δ-queues : queues/type]) + : result-type + . body) + ...) + #;#'(error "Not implemented yet"))] + + +@tc[Δ-Hash] is a type encapsulating both a hash, and a set of key-value pairs +added to the @tc[Δ-Hash] since its creation from a simple @tc[HashTable]. + +@chunk[<Δ-hash> + (define-type (Δ-Hash A B) + (Pairof (HashTable A B) + (Setof (Pairof A B)))) + + (: empty-Δ-hash (∀ (K V) (→ (Δ-Hash K V)))) + (define (empty-Δ-hash) + (cons ((inst hash K V)) ((inst set (Pairof K V))))) + + (: Δ-hash (∀ (K V) (→ (HashTable K V) (Δ-Hash K V)))) + (define (Δ-hash h) + (cons h ((inst set (Pairof K V))))) + + (: Δ-hash-add (∀ (K V) (→ (Δ-Hash K V) K V + (Δ-Hash K V)))) + (define (Δ-hash-add dh k v) + (if (hash-has-key? (car dh) k) + dh + (cons (hash-set (car dh) k v) + (set-add (cdr dh) (cons k v)))))] + +@section{Conclusion} + +@chunk[ + (module main typed/racket + (require (for-syntax syntax/parse + racket/syntax + "../lib/low-untyped.rkt") + "../lib/low.rkt") + + (provide fold-queues) + + <Δ-hash> + )] + +@chunk[ + (module* test typed/racket + (require (submod "..") + typed/rackunit) + + ; TODO + + (require (submod ".." doc)))] + +@chunk[<*> + (begin + + + (require 'main) + (provide (all-from-out 'main)) + + )] +