|
725 | 725 |
|
726 | 726 | (define-pass derive-type-constraints : L6-with-coercion (e) -> L7 ()
|
727 | 727 | (definitions
|
728 |
| - ; TODO: move the introduction of these type-variables to earlier pass |
729 | 728 | (define typevar-counter 0)
|
730 | 729 | (with-output-language (L7 Type)
|
731 | 730 | (define fresh-typevar
|
|
927 | 926 | (define (unify cs)
|
928 | 927 | (if (null? cs)
|
929 | 928 | (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)]) |
950 | 930 | (if (overloaded-constraint? c)
|
951 | 931 | (letrec ([find-first (lambda (alts)
|
952 | 932 | (cond
|
953 | 933 | [(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))]))]) |
957 | 936 | (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])))))) |
959 | 955 |
|
960 | 956 | (define-language
|
961 | 957 | L8
|
|
1538 | 1534 | (if (== $n $m)
|
1539 | 1535 | (apply (global $Array $map2) $f $v $w)
|
1540 | 1536 | (apply $length_error ,mlf-unit)))))
|
1541 |
| - ($foldr (lambda ($f $b $v) (apply (global $Array $fold_right) $f $v $b))) |
1542 | 1537 | ($reduce (lambda ($f $v)
|
1543 | 1538 | (let
|
1544 | 1539 | ($n (length $v))
|
|
0 commit comments