Add :query-type/args.
Shows return type for a given function with given argument types. original commit: 674c71103b65d5ac8467433def7c4542e01985a3
This commit is contained in:
parent
3a09c5d6df
commit
806c02c533
|
@ -200,6 +200,8 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
|||
(error ":type is only valid at the top-level of an interaction"))
|
||||
(define-syntax (:print-type stx)
|
||||
(error ":print-type is only valid at the top-level of an interaction"))
|
||||
(define-syntax (:query-type/args stx)
|
||||
(error ":query-type/args is only valid at the top-level of an interaction"))
|
||||
(define-syntax (:query-type/result stx)
|
||||
(error ":query-type/result is only valid at the top-level of an interaction"))
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
(for-template racket/base)
|
||||
(private with-types type-contract parse-type)
|
||||
(except-in syntax/parse id)
|
||||
racket/match racket/syntax unstable/match racket/list
|
||||
racket/match racket/syntax unstable/match racket/list syntax/stx
|
||||
(types utils abbrev generalize)
|
||||
(typecheck provide-handling tc-toplevel tc-app-helper)
|
||||
(rep type-rep)
|
||||
|
@ -61,6 +61,19 @@
|
|||
(match type
|
||||
[(tc-result1: t f o) t]
|
||||
[(tc-results: t) (cons 'Values t)])))))]
|
||||
;; given a function and input types, display the result type
|
||||
[(_ . ((~literal :query-type/args) op:expr arg-type:expr ...))
|
||||
(with-syntax ([(dummy-arg ...) (generate-temporaries #'(arg-type ...))])
|
||||
#`(display #,(tc-setup #'stx
|
||||
;; create a dummy function with the right argument types
|
||||
#`(lambda #,(stx-map (lambda (a t)
|
||||
(syntax-property a 'type-label t))
|
||||
#'(dummy-arg ...) #'(arg-type ...))
|
||||
(op dummy-arg ...))
|
||||
'top-level expanded init tc-toplevel-form before type
|
||||
(format "~a\n"
|
||||
(match type
|
||||
[(tc-result1: (and t (Function: _)) f o) t])))))]
|
||||
;; given a function and a desired return type, fill in the blanks
|
||||
[(_ . ((~literal :query-type/result) op:expr desired-type:expr))
|
||||
(let ([expected (parse-type #'desired-type)])
|
||||
|
|
|
@ -14,6 +14,9 @@ The following bindings are only available at the Typed Racket REPL.
|
|||
@defform[(:print-type e)]{Prints the type of @racket[_e]. This prints the whole
|
||||
type, which can sometimes be quite large.}
|
||||
|
||||
@defform[(:query-type/args f t ...)]{Given a function @racket[f] and argument
|
||||
types @racket[t], shows the result type of @racket[f].}
|
||||
|
||||
@defform[(:query-type/result f t)]{Given a function @racket[f] and a desired
|
||||
return type @racket[t], shows the arguments types @racket[f] should be given to
|
||||
return a value of type @racket[t].}
|
||||
|
|
Loading…
Reference in New Issue
Block a user