Skip to content

Commit f199e47

Browse files
committed
more progress on bounded polymorphism
1 parent 2c0cf9b commit f199e47

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

typed-racket-lib/typed-racket/infer/infer-unit.rkt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@
596596

597597
;; variables that are in X and should be constrained
598598
;; all other variables are compatible only with themselves
599-
[((and (F: (? (inferable-var? context))) S) T)
599+
[((F: (? (inferable-var? context))) T)
600600
#:return-when
601601
(match T
602602
;; fail when v* is an index variable
@@ -606,7 +606,7 @@
606606
;; constrain S to be below T (but don't mention bounds)
607607
(constrain S T #:above #f)]
608608

609-
[(S (and (F: (? (inferable-var? context))) T))
609+
[(S (F: (? (inferable-var? context))))
610610
#:return-when
611611
(match S
612612
[(F: v*) (and (bound-index? v*) (not (bound-tvar? v*)))]
@@ -623,6 +623,10 @@
623623
(let ([s (resolve-once s)])
624624
(and s (cg s t obj)))]
625625

626+
[((F: var (? Type? bound)) t)
627+
(let ([s (resolve-once bound)])
628+
(and s (cg s t obj)))]
629+
626630
;; constrain b1 to be below T, but don't mention the new vars
627631
[((Poly: v1 b1) T) (cgen (context-add context #:bounds v1) b1 T)]
628632

typed-racket-lib/typed-racket/rep/type-rep.rkt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,12 @@
16911691
(int-err "Wrong number of names: expected ~a got ~a" n (length names)))
16921692
(instantiate-type body
16931693
(map (lambda (n)
1694-
(make-F n (hash-ref new-bounds n #f)))
1694+
(define v (match (hash-ref new-bounds n #f)
1695+
[(App: rator (list (F: vb _)))
1696+
#:when (hash-has-key? new-bounds vb)
1697+
(make-App rator (list (hash-ref new-bounds vb)))]
1698+
[_else _else]))
1699+
(make-F n v))
16951700
names))]))
16961701

16971702
;; PolyDots 'smart' constructor

typed-racket-test/succeed/bounded-poly.rkt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@
1717
(number->string a))
1818

1919
(c-func 10 (foo 10))
20+
21+
(: d-func (All ([X <: Integer] [Y <: (Foo X)])
22+
(-> X Y String)))
23+
(define (d-func a b)
24+
(number->string (foo-a b)))
25+
26+
(d-func 42 (foo 10))

0 commit comments

Comments
 (0)