5 Utilities
Typed Racket provides some additional utility functions to facilitate typed programming.
See also the cast form.
Examples: | |||||||||||||||||||||
|
syntax
(with-asserts ([id maybe-pred] ...) body ...+)
maybe-pred =
| predicate
syntax
(typecheck-fail orig-stx maybe-msg maybe-id)
maybe-msg =
| msg-string maybe-id =
| #:covered-id id
Examples: | |||||||||||||||||||||||||||
|
5.1 Untyped Utilities
(require typed/untyped-utils) | |
package: typed-racket-more |
These utilities help interface typed with untyped code, particularly typed libraries that use types that cannot be converted into contracts, or export syntax transformers that must expand differently in typed and untyped contexts.
syntax
(require/untyped-contract maybe-begin module [name subtype] ...)
maybe-begin =
| (begin expr ...)
(require/untyped-contract "my-numerics.rkt" [negate (-> Integer Integer)])
(provide matrix-expt) (require/untyped-contract (begin (require "private/matrix/matrix-types.rkt")) "private/matrix/matrix-expt.rkt" [matrix-expt ((Matrix Number) Integer -> (Matrix Number))])
If an identifier name is imported using require/untyped-contract, reexported, and imported into typed code, it has its original type, not subtype. In other words, subtype is used only to generate a contract for name, not to narrow its type.
Because of limitations in the macro expander, require/untyped-contract cannot currently be used in typed code.
syntax
(define-typed/untyped-identifier name typed-name untyped-name)
(provide my-filter) (define-typed/untyped-identifier my-filter typed:my-filter untyped:my-filter)
Avoid this if possible. Use only in cases where a type has no subtype that can be converted to a contract; i.e. cases in which require/untyped-contract cannot be used.
procedure
This is the nuclear option, provided because it is sometimes, but rarely, useful. Avoid.