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:

#lang typed/racket

(require plot
         pict)

(vc-append (cast (plot-pict (function sin 0 1))
                 pict))

and the output is a graph, as expected.

Here’s some that fails a type-check:

#lang typed/racket

(require plot
         pict)

(vc-append (plot-pict (function sin 0 1)))

Error output:

;  plot-pict-test.rkt:6:11: Type Checker: type mismatch
;   expected: pict
;   given: Pict
;   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. 

Best,



Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/E0426BDB-9B8A-4AE9-8550-3871ACC6BF2A%40timjervis.com.

Reply via email to