Skip to content

Commit 816cd44

Browse files
committed
parse-type: inline type applications for simple type constructors
1 parent 4be1a51 commit 816cd44

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

typed-racket-lib/typed-racket/private/parse-type.rkt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,13 +1385,20 @@
13851385
(lambda (e)
13861386
(match-define (exn:fail:contract:arity:type-constructor _ _ expected given) e)
13871387
(err expected given))])
1388-
(define alias (lookup-type-alias #'id (lambda (x) x) (lambda () #f)))
1389-
(match alias
1390-
[(? Name?)
1391-
(if (equal? arity (length args^))
1392-
(make-App alias args^)
1393-
(err arity (length args^)))]
1394-
[_ (apply rator args^)]))]
1388+
(cond
1389+
;; in the checking mode, inline type applications of simple
1390+
;; type constructors
1391+
[(and (not mode)
1392+
(simple-type-constructor? #'id))
1393+
(apply rator args^)]
1394+
[else
1395+
(define alias (lookup-type-alias #'id (lambda (x) x) (lambda () #f)))
1396+
(match alias
1397+
[(? Name?)
1398+
(if (equal? arity (length args^))
1399+
(make-App alias args^)
1400+
(err arity (length args^)))]
1401+
[_ (apply rator args^)])]))]
13951402
[(? Name?)
13961403
(resolve-app-check-error rator args^ stx)
13971404
(define app (make-App rator args^))

typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"../find-annotation.rkt"
1111
"../tc-metafunctions.rkt"
1212
"../../types/abbrev.rkt"
13-
"../../types/resolve.rkt"
1413
"../../types/utils.rkt"
1514
"../../types/generalize.rkt"
15+
"../../types/resolve.rkt"
1616
"../../types/type-table.rkt"
1717
"../../private/type-annotation.rkt"
1818
"../../private/syntax-properties.rkt"
@@ -109,8 +109,9 @@
109109
(generalize (tc-expr/t ac)))))]
110110
[acc-ty (or
111111
(type-annotation #'val #:infer #t)
112-
(match (resolve expected)
113-
[(tc-result1: (app resolve (and t (Listof: _)))) t]
112+
(match expected
113+
[(tc-result1: (and t (or (? App? (app resolve-once (Listof: _))) (Listof: _))))
114+
t]
114115
[_ #f])
115116
(generalize -Null))])
116117
;; this check is needed because the type annotation may come

typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-list.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"../../types/type-table.rkt"
1313
"../../types/utils.rkt"
1414
"../../types/substitute.rkt"
15+
"../../types/resolve.rkt"
1516
"../../rep/type-rep.rkt"
1617
"../../env/tvar-env.rkt"
1718
(prefix-in i: "../../infer/infer.rkt")
@@ -154,7 +155,7 @@
154155
;; special case for `reverse' to propagate expected type info
155156
(pattern ((~and fun (~or reverse k:reverse)) arg)
156157
(match expected
157-
[(tc-result1: (and return-ty (Listof: _)))
158+
[(tc-result1: (and return-ty (or (? App? (app resolve-once (Listof: _))) (Listof: _))))
158159
(begin0
159160
(tc-expr/check #'arg expected)
160161
(add-typeof-expr #'fun (ret (-> return-ty return-ty))))]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#lang typed/racket
2+
3+
(define-type (Assoc X Y) (Listof (Pairof X Y)))
4+
5+
(: f : (Listof Integer) (Listof String) -> (Listof (Pairof Integer String)))
6+
(define (f l m)
7+
(for/list : (Assoc Integer String) ([x : Integer (in-list l)]
8+
[y : String (in-list m)])
9+
(cons x y)))
10+
11+
12+
(define (g [l : (Listof Integer)] [m : (Listof String)]) : (Assoc Integer String)
13+
(for/list ([x (in-list l)]
14+
[y (in-list m)])
15+
(cons x y)))

0 commit comments

Comments
 (0)