Pict and pict types

27 views
Skip to first unread message

Tim Jervis

unread,
Nov 24, 2020, 6:24:17 AM11/24/20
to racket...@googlegroups.com
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

Alex Harsanyi

unread,
Nov 24, 2020, 7:00:12 AM11/24/20
to Racket Users
Reply all
Reply to author
Forward
0 new messages