diff --git a/graph/graph/__DEBUG_graph_1__.rkt b/graph/graph/__DEBUG_graph_1__.rkt index bbb5d96..6fc8cf3 100644 --- a/graph/graph/__DEBUG_graph_1__.rkt +++ b/graph/graph/__DEBUG_graph_1__.rkt @@ -1,46 +1,47 @@ #lang typed/racket -#| (module m typed/racket (define foo (let () - (define-type Foo (Pairof (Promise Foo) Number)) + (define-type Foo (List 'foo (U Bar One))) + (define-type Bar (List 'bar (U Foo Zero))) - (define (f [n : Number]) : Foo - (cons (delay (f (add1 n))) - n)) - (f 1))) + (ann (list 'foo (list 'bar 0)) Foo))) (provide foo)) (require 'm) -(force (car foo)) -|# -(define-type (P A) (Pairof (U A Null) (U A Null))) +;(: f (∀ (A) (→ (List Symbol A) A))) +;(define (f x) (cadr x)) -(define bar - (let () - (define-type Bar (Pairof (P Bar) Number)) +;(unpack (s-f foo)) - (define (f [n : Number]) : Bar - (cons (ann (cons '() '()) (P Bar)) - n)) - - (f 1))) - -(provide P bar) +(cadr foo) #| -(define foo - (let () - ;(define-type Foo (Rec F (Pairof (Promise F) Number))) - (define-type Foo (Pairof (Promise Foo) Number)) - - (define (f [n : Number]) : Foo - (cons (delay (f (add1 n))) - n)) - (f 1))) +(module m typed/racket + (struct (A) s ([f : A])) + (define foo + (let () + (define-type Foo (List 'foo (U (s Foo) (s Bar) One))) + (define-type Bar (List 'bar (U (s Foo) (s Bar) Zero))) + + (ann (s (list 'foo 1)) (s Foo)))) -(provide foo) + ;(: unpack (∀ (A) (→ (List Symbol A) A))) + ;(define (unpack x) (cadr x)) + + (provide (struct-out s) + ;unpack + foo)) + +(require 'm) + +;(: f (∀ (A) (→ (List Symbol A) A))) +;(define (f x) (cadr x)) + +;(unpack (s-f foo)) + +(s-f foo) |# \ No newline at end of file diff --git a/graph/graph/__DEBUG_graph__.rkt b/graph/graph/__DEBUG_graph__.rkt index bbf98f0..fb08c0e 100644 --- a/graph/graph/__DEBUG_graph__.rkt +++ b/graph/graph/__DEBUG_graph__.rkt @@ -1,15 +1,36 @@ #lang debug typed/racket (require (submod "graph3.lp2.rkt" test)) +(require "../lib/low.rkt") (require racket/list) -;#R(force (second g)) +(define #:∀ (A) (map-force [l : (Listof (Promise A))]) + (map (inst force A) l)) -(ann g 1) +(let () + (map-force (second g)) + (cars (map-force (second g))) + (map-force (third g)) + (map-force (append* (cars (cdrs (cdrs (map-force (second g))))))) + (void)) #| -#R(force (caadr (force (car (second g))))) -#R(map force (second g)) +#R(map-force (second g)) +#R(map-force (third g)) -#R(map force (third g)) -|# \ No newline at end of file +(newline) + +#R(force (car (second g))) +#R(force (cadr (force (car (caddr (force (car (second g)))))))) +;|# + +(newline) + +(define (forceall [fuel : Integer] [x : Any]) : Any + (if (> fuel 0) + (cond [(list? x) (map (curry forceall fuel) x)] + [(promise? x) (forceall (sub1 fuel) (force x))] + [else x]) + x)) + +(forceall 5 g) diff --git a/graph/graph/__DEBUG_graph_lift__.rkt b/graph/graph/__DEBUG_graph_lift__.rkt index 92d5ca2..0c9b75f 100644 --- a/graph/graph/__DEBUG_graph_lift__.rkt +++ b/graph/graph/__DEBUG_graph_lift__.rkt @@ -2,8 +2,8 @@ (define-syntax (l stx) #`(let () - #,(syntax-local-lift-expression #'(begin (define-type Foo (List 'foo Foo Bar One)) (void))) - #,(syntax-local-lift-expression #'(begin (define-type Bar (List 'foo Foo Bar One)) (void))) + (syntax-local-lift-expression (define-type Foo (List 'foo Foo Bar One))) + (syntax-local-lift-expression (define-type Bar (List 'foo Foo Bar One))) 1)) (l) \ No newline at end of file diff --git a/graph/graph/__DEBUG_graph_no_forall__.rkt b/graph/graph/__DEBUG_graph_no_forall__.rkt new file mode 100644 index 0000000..dbdb2e7 --- /dev/null +++ b/graph/graph/__DEBUG_graph_no_forall__.rkt @@ -0,0 +1,21 @@ +#lang typed/racket + +(module m typed/racket + (define-values (x f) + (let () + (define-type X (List (U X Null))) + + (define (f [x : X]) : Integer + (if (null? (car x)) + 0 + (add1 (f (car x))))) + + (define x : X (list (list (list '())))) + + (values x f))) + + (provide x f)) + +(require 'm) + +(f x) \ No newline at end of file diff --git a/graph/graph/fold-queues.lp2.rkt b/graph/graph/fold-queues.lp2.rkt index 4a0da82..2910391 100644 --- a/graph/graph/fold-queues.lp2.rkt +++ b/graph/graph/fold-queues.lp2.rkt @@ -125,10 +125,7 @@ database type opaque, and use an accessor with signature @subsubsection{Popping elements from the queues} @chunk[<Δ-hash2-dequeue> - (: Δ-hash2-dequeue (case→ (→ (List (HashTable Element-Type Index) - (Listof Element-Type) ;; TODO: (P (L)) - (Listof Element-Type) ;; TODO: (P (L)) - Index) + (: Δ-hash2-dequeue (case→ (→ <Δ-hash2-queue-type> (values Element-Type <Δ-hash2-queue-type>)) …)) @@ -192,7 +189,7 @@ position in the vector equal to the index associated to it in the hash table: (match-let ([(list name/queue …) (ann Δ-results (List (Listof Result-Type) …))]) (list (vector->immutable-vector - (ann (list->vector name/queue) + (ann (list->vector (reverse name/queue)) (Vectorof Result-Type))) …)))] @@ -212,7 +209,6 @@ position in the vector equal to the index associated to it in the hash table: … [else (Δ-results-to-vectors results)]))) - #;(process-queues (list ((inst empty-Δ-hash Element-Type Index)) …)) (% index Δ-hash = (Δ-hash2-enqueue 'root-name root-value Δ-hash2-empty) (process-queues Δ-hash Δ-results-empty))] diff --git a/graph/graph/graph3.lp2.rkt b/graph/graph/graph3.lp2.rkt index 2c25e1f..f9ad9b8 100644 --- a/graph/graph/graph3.lp2.rkt +++ b/graph/graph/graph3.lp2.rkt @@ -30,7 +30,7 @@ these constructors: @chunk[ [City [streets : (Listof Street)] [people : (Listof Person)] ] - [Street [houses : (Listof House)] ] + [Street [name : String] [houses : (Listof House)] ] [House [owner : Person] [location : Street] ] [Person [name : String] ]] @@ -41,13 +41,13 @@ same street. In order to build a graph with that type, we start from the root parameters. Here, we will take a representation of the city as a list of -@tc[(street . person-name)] pairs, and will convert it to a more convenient +@tc[(street-name . person-name)] pairs, and will convert it to a more convenient graph representation. Our single root parameter will thus be the whole list: @chunk[ - '(["Amy" . "Ada street"] - ["Jack" . "J street"] - ["Anabella" . "Ada street"])] + '(["Amy" . "Ada Street"] + ["Jack" . "J Street"] + ["Anabella" . "Ada Street"])] We will then provide a mapping from the root parameter to the root node, in our case @tc[City]. When processing the root parameter, one can call other mappings @@ -73,10 +73,10 @@ whole city @tc[c] in list form, and creates a @tc[Street] node. @chunk[ [(m-street [c : (Listof (Pairof String String))] [s : String]) - (Street (map (curry (curry m-house s) c) - (cars (filter (λ ([x : (Pairof String String)]) - (equal? (cdr x) s)) - c))))]] + (Street s (map (curry (curry m-house s) c) + (cars (filter (λ ([x : (Pairof String String)]) + (equal? (cdr x) s)) + c))))]] The @tc[m-house] mapping defined below calls back the @tc[m-street] mapping, to store for each house a reference to the containing street. Normally, this would @@ -86,10 +86,10 @@ the mappings aren't called directly, and instead, in the body of @tc[m-house], us to not worry about mutually recursive mappings: a mapping can be called any number of times with the same data, it will actually only be run once. -The @tc[make-graph-constructor] macro will post-process the result of each -mapping, and replace the placeholders with promises for the the result of the -mapping. The promises are not available during graph construction, so there is -no risk of forcing one before it is available. +The @tc[define-graph] macro will post-process the result of each mapping, and +replace the placeholders with promises for the the result of the mapping. The +promises are not available during graph construction, so there is no risk of +forcing one before it is available. We can now write the @tc[m-house] and @tc[m-person] mappings. @@ -105,14 +105,13 @@ We can now write the @tc[m-house] and @tc[m-person] mappings. @subsubsection{Creating an instance of the graph} -For now, we will supply directly the root arguments to the @tc[make-graph] +For now, we will supply directly the root arguments to the @tc[define-graph] macro, as well as the node types and mappings. We can later curry the macro, so that it first takes the node types and mappings, and produces a lambda taking the root arguments as parameters. @chunk[ - (define g - (make-graph () ))] + (define-graph g () )] @subsection{More details on the semantics} @@ -145,17 +144,18 @@ with @tc[Rec] yet. @section{Implementation} -In this section, we will describe how the @tc[make-graph] macro is implemented. +In this section, we will describe how the @tc[define-graph] macro is +implemented. @subsection{The macro's syntax} -We use a simple syntax for @tc[make-graph], and make it more flexible through +We use a simple syntax for @tc[define-graph], and make it more flexible through wrapper macros. @chunk[ - (make-graph ([node ] - …) - root-expr:expr …)] + (define-graph name ([node ] + …) + root-expr:expr …)] Where @tc[] is: @@ -574,30 +574,32 @@ are replaced by tagged indices: @section{Putting it all together} -@chunk[ +@chunk[ (define-syntax/parse #|((λ (x) (pretty-write (syntax->datum x)) x)|# (template - (let () + ;(let () + (begin (begin ) … (begin ) … (begin ) … (begin ) … (begin ) … (begin ) … - (let*-values ([(rs) ] - [(node/database rs) - (values (ann (car rs) - (Vectorof node/with-indices-type)) - (cdr rs))] - … - [(_) (ann rs Null)]) - (begin ) … - (list node/with-indices→with-promises …) - (ann (root/with-indices→with-promises - (vector-ref root/database 0)) - root/with-promises-type))))#|)|#)] + (define name : root/with-promises-type + (match-let ([(list node/database …) ]) + #|(let*-values ([(rs) ] + [(node/database rs) + (values (ann (car rs) + (Vectorof node/with-indices-type)) + (cdr rs))] + … + [(_) (ann rs Null)])|# + (begin ) … + ;(list node/with-indices→with-promises …) + (root/with-indices→with-promises + (vector-ref root/database 0))))))#|)|#)] @section{Conclusion} @@ -620,8 +622,8 @@ are replaced by tagged indices: ;(begin-for-syntax ;) - (provide make-graph) - )] + (provide define-graph) + )] @chunk[ (module* test typed/racket @@ -631,10 +633,8 @@ are replaced by tagged indices: "../lib/low.rkt"; DEBUG typed/rackunit) - - (provide g) - g + (require (submod ".." doc)))]