Skip to content

Commit fec564d

Browse files
committed
Normalize types more strongly for quantification inside qualification
This improves how certain types signatures are displayed to the user, made much more visible by the new type tooltips.
1 parent d67ed5c commit fec564d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

hackett-lib/hackett/private/type-language.rkt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,17 @@
157157
(syntax-track-origin #'t-.residual #'head)
158158
(syntax-track-origin #'expansion #'head))]
159159
[pattern (head:#%type:qual ~! {~var a (type intdef-ctx)} {~var b (type intdef-ctx)})
160-
#:attr expansion (syntax/loc/props this-syntax
161-
(head a.expansion b.expansion))
160+
#:do [(define outer-this-syntax this-syntax)]
161+
; There’s never really any reason to have a #%type:forall immediately inside a
162+
; #%type:qual, and users don’t expect to see such types, so push #%type:qual down when it
163+
; appears immediately around a #%type:forall.
164+
#:attr expansion (syntax-parse #'b.expansion
165+
[(~#%type:forall* [x ...+] t)
166+
(quasisyntax/loc/props this-syntax
167+
(?#%type:forall* [x ...] #,(syntax/loc/props outer-this-syntax
168+
(head a.expansion t))))]
169+
[_ (syntax/loc/props outer-this-syntax
170+
(head a.expansion b.expansion))])
162171
#:attr scoped-binding-ctxs '()
163172
#:attr residual (~> #'(values)
164173
(syntax-track-origin #'a.residual #'head)
@@ -187,7 +196,7 @@
187196
(define (expand-type stx [intdef-ctx #f])
188197
(syntax-parse stx
189198
#:context 'expand-type
190-
[{~var t (type intdef-ctx)} #'t.expansion])))
199+
[{~var t (type intdef-ctx)} #'t.expansion]))
191200

192201
;; ---------------------------------------------------------------------------------------------------
193202
;; helper expanders / metafunctions
@@ -199,7 +208,6 @@
199208
; {?#%type:app Either String Integer}. Similar helpers are provided for nested foralls and nested
200209
; qualifications.
201210

202-
(begin-for-syntax
203211
(define-syntax-class nested-apps
204212
#:description #f
205213
#:attributes [[linearized 1]]

0 commit comments

Comments
 (0)