11 Unsafe Typed Racket operations
(require typed/racket/unsafe) | package: typed-racket-lib |
Warning: the operations documented in this section are unsafe, meaning that they can circumvent the invariants of the type system. Unless the #:no-optimize language option is used, this may result in unpredictable behavior and may even crash Typed Racket.
Unlike require/typed, this form is unsafe and will not generate contracts that correspond to the specified types to check that the values actually match their types.
> (require typed/racket/unsafe) ; import with a bad type > (unsafe-require/typed racket/base [values (-> String Integer)]) ; unchecked call, the result type is wrong > (values "foo") - : Integer
"foo"
Added in version 1.3 of package typed-racket-lib.
Changed in version 1.6: Added support for struct type variables
Unlike provide, this form is unsafe and Typed Racket will not generate any contracts that correspond to the specified types. This means that uses of the exports in other modules may circumvent the type system’s invariants.
Additionally, importing an identififer that is exported with unsafe-provide into another typed module, and then re-exporting it with provide will not cause contracts to be generated.
Uses of the provided identifiers in other typed modules are not
affected by unsafe-provide—
> (module t typed/racket/base (require typed/racket/unsafe) (: f (-> Integer Integer)) (define (f x) (add1 x)) ; unsafe export, does not install checks (unsafe-provide f))
> (module u racket/base (require 't) ; bad call that's unchecked (f "foo")) > (require 'u) add1: contract violation
expected: number?
given: "foo"
Added in version 1.3 of package typed-racket-lib.