Add a function to print whole types.

With this, it's possible to get more information than the simplified
types shown at the REPL. The types are as unwieldy as ever, but you
have to ask for them explicitly.

This is not an adequate long-term solution, and will be replaced by a
"Type Explorer" tool.
This commit is contained in:
Vincent St-Amour 2011-07-19 17:27:25 -04:00
parent 1a66f60eb4
commit 70e1d63bed
3 changed files with 19 additions and 4 deletions

View File

@ -37,8 +37,9 @@ This file defines two sorts of primitives. All of them are provided into any mod
racket/flonum ; for for/flvector and for*/flvector racket/flonum ; for for/flvector and for*/flvector
mzlib/etc mzlib/etc
(for-syntax (for-syntax
racket/match
syntax/parse syntax/parse
racket/syntax racket/syntax
racket/base racket/base
racket/struct-info racket/struct-info
syntax/struct syntax/struct
@ -49,7 +50,9 @@ This file defines two sorts of primitives. All of them are provided into any mod
"../utils/tc-utils.rkt" "../utils/tc-utils.rkt"
"../env/type-name-env.rkt" "../env/type-name-env.rkt"
"../private/type-contract.rkt" "../private/type-contract.rkt"
"for-clauses.rkt") "for-clauses.rkt"
"../typecheck/tc-toplevel.rkt"
"../types/utils.rkt")
"../types/numeric-predicates.rkt") "../types/numeric-predicates.rkt")
(provide index?) ; useful for assert, and racket doesn't have it (provide index?) ; useful for assert, and racket doesn't have it
@ -172,6 +175,15 @@ This file defines two sorts of primitives. All of them are provided into any mod
[(_ ty:expr) [(_ ty:expr)
#`(display #,(format "~a\n" (parse-type #'ty)))])) #`(display #,(format "~a\n" (parse-type #'ty)))]))
;; Prints the _entire_ type. May be quite large.
(define-syntax (:print-type stx)
(syntax-parse stx
[(_ e:expr)
#`(display #,(format "~a\n"
(match (tc-toplevel-form #'e)
[(tc-result1: t f o) t]
[(tc-results: t) (cons 'Values t)])))]))
(define-syntax (require/opaque-type stx) (define-syntax (require/opaque-type stx)
(define-syntax-class name-exists-kw (define-syntax-class name-exists-kw
(pattern #:name-exists)) (pattern #:name-exists))

View File

@ -73,7 +73,7 @@
#f] #f]
[(tc-result1: t f o) [(tc-result1: t f o)
(let-values ([(t pruned?) (cleanup-type t)]) (let-values ([(t pruned?) (cleanup-type t)])
(format "- : ~a~a\n" t (if pruned? " and more..." "")))] (format "- : ~a~a\n" t (if pruned? "\nUse :print-type to see more." "")))]
[(tc-results: t) [(tc-results: t)
;; map the first component and ormap the second. ;; map the first component and ormap the second.
(define-values (ts any-pruned?) (define-values (ts any-pruned?)
@ -84,7 +84,7 @@
(values (cons t ts) (or pruned? new-pruned?))))) (values (cons t ts) (or pruned? new-pruned?)))))
(format "- : ~a~a\n" (format "- : ~a~a\n"
(cons 'Values (reverse ts)) (cons 'Values (reverse ts))
(if any-pruned? " and more...\n" ""))] (if any-pruned? " \nUse :print-type to see more." ""))]
[x (int-err "bad type result: ~a" x)])]) [x (int-err "bad type result: ~a" x)])])
(if ty-str (if ty-str
#`(let ([type '#,ty-str]) #`(let ([type '#,ty-str])

View File

@ -12,6 +12,9 @@ These features are currently experimental and subject to change.
@defform[(:type t)]{Prints the type @racket[_t].} @defform[(:type t)]{Prints the type @racket[_t].}
@defform[(:print-type e)]{Prints the type of @racket[_e]. This prints the whole
types, which can sometimes be quite large.}
@defform[(declare-refinement id)]{Declares @racket[id] to be usable in @defform[(declare-refinement id)]{Declares @racket[id] to be usable in
refinement types.} refinement types.}