Hi everyone,
In typed racket, vc-append expects arguments of type pict, while plot-pict produces results of type Pict. Therefore, to have vc-append accept a plot-pict argument, I’m currently casting the result of plot-pict to be of type pict.
From my understanding of the underlying racket code, Pict just invokes a pict? predicate through an #opaque definition, and cast inserts a runtime test of its argument. Therefore, my cast seems wasteful. Have I missed something? Is there a better way to structure a solution that type-checks?
Here’s some code that type-checks for me:
(vc-append (cast (plot-pict (function sin 0 1))
and the output is a graph, as expected.
Here’s some that fails a type-check:
(vc-append (plot-pict (function sin 0 1)))
Error output:
; plot-pict-test.rkt:6:11: Type Checker: type mismatch
; in: (plot-pict (function sin 0 1))
; Context (plain; to see better errortrace context, re-run with C-u prefix):
; /Applications/Racket/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:376:0 type-check
; /Applications/Racket/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:619:0 tc-module
; /Applications/Racket/share/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:96:12
; /Applications/Racket/share/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:23:4
I get the same results whether I require pict or typed/pict.
I hope this question is of general interest. I have some familiarity with regular racket, but I’m only just starting out on typed racket.