From 7a6aadd1871462f2f7296f9cb5e26bb46bf57f6c Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Tue, 11 Mar 2025 23:22:26 -0300 Subject: [PATCH] Some kind of implementations --- Labs/06.rkt | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Labs/06.rkt b/Labs/06.rkt index bae09ed..81275b9 100644 --- a/Labs/06.rkt +++ b/Labs/06.rkt @@ -3,11 +3,58 @@ [mt] [node (b : (Boxof (Optionof Number))) (l : BoxTree) (r : BoxTree)]) +#;(define (unify-trees! t1 t2) + (cond + [(and (mt? t1) (mt? t2)) (void)] + [(or (mt? t1) (mt? t2)) (error 'unify-trees! "shape mismatch")] + [else + (let* ([t1-l (node-l t1)] + [t1-r (node-r t1)] + [t2-l (node-l t2)] + [t2-r (node-r t2)]) + (begin + (type-case BoxTree t1-l + [(node b l r) (type-case (Optionof Number) (unbox b) + [(some b) (set-box! (node-b t1-r) (unbox (node-b t2-r)))] + [(none) (set-box! (node-b t1-l) (unbox (node-b t2-l)))])] + [else (void)]) + (type-case BoxTree t2-l + [(node b l r) (type-case (Optionof Number) (unbox b) + [(some b) (set-box! (node-b t2-r) (unbox (node-b t1-r)))] + [(none) (set-box! (node-b t2-l) (unbox (node-b t1-l)))])] + [else (unify-trees! )])))])) + +#;(define (unify-trees! t1 t2) + (cond + [(and (mt? t1) (mt? t2)) (void)] + [(or (mt? t1) (mt? t2)) (error 'unify-trees! "shape mismatch")] + [else + (let* ([t1-l (node-l t1)] + [t1-r (node-r t1)] + [t2-l (node-l t2)] + [t2-r (node-r t2)]) + (begin + (type-case BoxTree t1-l + [(node b l r) (type-case (Optionof Number) (unbox b) + [(some b) (set-box! (node-b t1-r) (unbox (node-b t2-r)))] + [(none) (set-box! (node-b t1-l) (unbox (node-b t2-l)))])] + [else (void)]) + (type-case BoxTree t2-l + [(node b l r) (type-case (Optionof Number) (unbox b) + [(some b) (set-box! (node-b t2-r) (unbox (node-b t1-r)))] + [(none) (set-box! (node-b t2-l) (unbox (node-b t1-l)))])] + [else (void)]) + (unify-trees! t1-l t1-r) + (unify-trees! t2-l t2-r)))])) + (define (unify-trees! t1 t2) (cond [(and (mt? t1) (mt? t2)) (void)] [(or (mt? t1) (mt? t2)) (error 'unify-trees! "shape mismatch")] - [( + [else + + + (module+ test ;; Same shape, one "variable" in each