Skip to content

Commit 934f81c

Browse files
committed
Clean up the code a bit
1 parent 78209cc commit 934f81c

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

silly-k.scm

+21-26
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@
725725

726726
(define-pass derive-type-constraints : L6-with-coercion (e) -> L7 ()
727727
(definitions
728-
; TODO: move the introduction of these type-variables to earlier pass
729728
(define typevar-counter 0)
730729
(with-output-language (L7 Type)
731730
(define fresh-typevar
@@ -927,35 +926,32 @@
927926
(define (unify cs)
928927
(if (null? cs)
929928
(lambda (x) x)
930-
(let* ([c (car cs)]
931-
[cs^ (cdr cs)]
932-
[go (lambda (s t)
933-
(cond
934-
[(equal? s t) (unify cs^)]
935-
[(and (typevar-type? s) (not (occurs s t)))
936-
(cond
937-
[(unify (substitute s t cs^)) => (lambda (f)
938-
(lambda (x) (f (substitute s t x))))]
939-
[else #f])]
940-
[(and (typevar-type? t) (not (occurs t s)))
941-
(cond
942-
[(unify (substitute t s cs^)) => (lambda (f)
943-
(lambda (x) (f (substitute t s x))))]
944-
[else #f])]
945-
[(and (lambda-type? s) (lambda-type? t))
946-
(unify (append (list (list (cadr s) (cadr t)) (list (caddr s) (caddr t))) cs^))]
947-
[(and (vector-type? s) (vector-type? t))
948-
(unify (append (list (list (cadr s) (cadr t))) cs^))]
949-
[else #f]))])
929+
(let* ([c (car cs)] [cs^ (cdr cs)])
950930
(if (overloaded-constraint? c)
951931
(letrec ([find-first (lambda (alts)
952932
(cond
953933
[(null? alts) #f]
954-
[else (cond
955-
[(unify (append (car alts) cs^))]
956-
[else (find-first (cdr alts))])]))])
934+
[(unify (append (car alts) cs^))]
935+
[else (find-first (cdr alts))]))])
957936
(find-first (cdr c)))
958-
(let ([s (car c)] [t (cadr c)]) (go s t))))))
937+
(let ([s (car c)] [t (cadr c)])
938+
(cond
939+
[(equal? s t) (unify cs^)]
940+
[(and (typevar-type? s) (not (occurs s t)))
941+
(cond
942+
[(unify (substitute s t cs^)) =>
943+
(lambda (f) (lambda (x) (f (substitute s t x))))]
944+
[else #f])]
945+
[(and (typevar-type? t) (not (occurs t s)))
946+
(cond
947+
[(unify (substitute t s cs^)) =>
948+
(lambda (f) (lambda (x) (f (substitute t s x))))]
949+
[else #f])]
950+
[(and (lambda-type? s) (lambda-type? t))
951+
(unify (append (list (list (cadr s) (cadr t)) (list (caddr s) (caddr t))) cs^))]
952+
[(and (vector-type? s) (vector-type? t))
953+
(unify (append (list (list (cadr s) (cadr t))) cs^))]
954+
[else #f]))))))
959955

960956
(define-language
961957
L8
@@ -1538,7 +1534,6 @@
15381534
(if (== $n $m)
15391535
(apply (global $Array $map2) $f $v $w)
15401536
(apply $length_error ,mlf-unit)))))
1541-
($foldr (lambda ($f $b $v) (apply (global $Array $fold_right) $f $v $b)))
15421537
($reduce (lambda ($f $v)
15431538
(let
15441539
($n (length $v))

0 commit comments

Comments
 (0)