From 65401d5bd8599af8c03d22d01eb680d25380202b Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 13 Sep 2011 13:49:04 -0400 Subject: [PATCH] Generalize types shown at the REPL, to keep types simple. original commit: 68d58f7d2acb887e3bca046ed369b31a058e4cfc --- collects/typed-racket/core.rkt | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/collects/typed-racket/core.rkt b/collects/typed-racket/core.rkt index 313f1dc4..d8a92b1f 100644 --- a/collects/typed-racket/core.rkt +++ b/collects/typed-racket/core.rkt @@ -88,19 +88,27 @@ [(tc-result1: t f o) ;; Don't display the whole types at the REPL. Some case-lambda types ;; are just too large to print. - (let ([tc (cleanup-type t)]) - (format "- : ~a~a\n" - tc - (cond [(equal? tc t) ""] - [did-I-suggest-:print-type-already? " ..."] - [else (set! did-I-suggest-:print-type-already? #t) - :print-type-message])))] + ;; Also, to avoid showing too precise types, we generalize types + ;; before printing them. + (define tc (cleanup-type t)) + (define tg (generalize tc)) + (format "- : ~a~a~a\n" + tg + (cond [(equal? tc tg) ""] + [else (format " (generalized from ~a)" tc)]) + (cond [(equal? tc t) ""] + [did-I-suggest-:print-type-already? " ..."] + [else (set! did-I-suggest-:print-type-already? #t) + :print-type-message]))] [(tc-results: t) - (define new-ts (map cleanup-type t)) - (format "- : ~a~a\n" - (cons 'Values new-ts) + (define tcs (map cleanup-type t)) + (define tgs (map generalize tcs)) + (format "- : ~a~a~a\n" + (cons 'Values tgs) + (cond [(andmap equal? tgs tcs) ""] + [else (format " (generalized from ~a)" (cons 'Values tcs))]) ;; did any get pruned? - (cond [(andmap equal? t new-ts) ""] + (cond [(andmap equal? t tcs) ""] [did-I-suggest-:print-type-already? " ..."] [else (set! did-I-suggest-:print-type-already? #t) :print-type-message]))]