Is there an unsafe version of the cast
function in Typed Racket?
I'd like to use this to be able to add a proposition that I logically know about, but the type system can't figure out.
For instance, I might have a predicate that checks that a list has exactly two elements:
#lang typed/racket
(: func (-> (Listof String) Boolean))
(define (func x) (eq? (length x) 2))
I'd like to inform the type system of a proposition that the input list has exactly two elements:
(: func2 (-> (Listof String) Boolean : (List String String)))
(define func2
(cast func (-> (Listof String) Boolean : (List String String))))
However, when trying to do this, I get an error like the following:
Type Checker: Type (-> (Listof String) Boolean : (List String String))
could not be converted to a contract: cannot generate contract for
function type with props or objects.
in: (-> (Listof String) Boolean : (List String String))
Is there some version of the cast
function where I can tell the type system, "Just trust me here."
I'm imagining this function being similar to unsafeCoerce
in Haskell.
type-expander
library provides an unsafe-cast macro: docs.racket-lang.org/type-expander-implementation/…. I wonder why this isn't provided directly by Typed Racket. - illabout