Skip to content

Commit 0f6da0b

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

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)