[racket] Weird typed racket error

From: Alexander D. Knauth (alexander at knauth.org)
Date: Sat Apr 19 22:54:57 EDT 2014

When I take out the #{} annotations, it gives me 24 errors (with some repeated) instead of just 6: (that’s the reason I put them there in the first place)
(: sphere3d (#:posn (Vectorof Real) #:r Nonnegative-Real [#:color Plot-Color] -> renderer3d))
(define (sphere3d #:posn ctr.posn #:r r #:color [color "black"])
  (let: ([ctr.x : Real (vector-x ctr.posn)]
         [ctr.y : Real (vector-y ctr.posn)]
         [ctr.z : Real (vector-z ctr.posn)])
    (isosurface3d (λ: ([x : Real] [y : Real] [z : Real])
                    (let: ([posn : (Vectorof Real) (vector x y z)])
                      (vmag^2 (v- posn ctr.posn))))
                  (ann (sqr r) Real)
                  (ann (- ctr.x r) (U Real False)) (ann (+ ctr.x r) (U Real False))
                  (ann (- ctr.y r) (U Real False)) (ann (+ ctr.y r) (U Real False))
                  (ann (- ctr.z r) (U Real False)) (ann (+ ctr.z r) (U Real False))
                  #:line-style 'transparent
                  #:color color)))

. Type Checker: Expected (Vectorof Real), but got Plot-Color in: ctr.posn
. Type Checker: Expected (Vectorof Real), but got Plot-Color in: ctr.posn
. Type Checker: Expected (Vectorof Real), but got Plot-Color in: ctr.posn
. Type Checker: Expected (Vectorof Real), but got Plot-Color in: ctr.posn
. Type Checker: Expected Real, but got True in: r
. Type Checker: Expected Real, but got True in: r
. Type Checker: Expected Real, but got True in: r
. Type Checker: Expected Real, but got True in: r
. Type Checker: Expected Real, but got True in: r
. Type Checker: Expected Real, but got True in: r
. Type Checker: Expected Real, but got True in: r
. Type Checker: No function domains matched in function application:
Types: (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) (U Real False) (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) -> renderer3d
       (Real Real Real -> Real) Real -> renderer3d
Arguments: (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) (U Real False) (U Real False) (U Real False)
Expected result: renderer3d
 in: (isosurface3d (λ: ((x : Real) (y : Real) (z : Real)) (let: ((posn : (Vectorof Real) (vector x y z))) (vmag^2 (v- posn ctr.posn)))) (ann (sqr r) Real) (ann (- ctr.x r) (U Real False)) (ann (+ ctr.x r) (U Real False)) (ann (- ctr.y r) (U Real False)) (ann (+ ctr.y r) (U Real False)) (ann (- ctr.z r) (U Real False)) (ann (+ ctr.z r) (U Real False)) #:line-style (quote transparent) #:color color)
. Type Checker: Expected (Vectorof Real), but got False in: ctr.posn
. Type Checker: Expected (Vectorof Real), but got False in: ctr.posn
. Type Checker: Expected (Vectorof Real), but got False in: ctr.posn
. Type Checker: Expected (Vectorof Real), but got False in: ctr.posn
. Type Checker: Expected Real, but got False in: r
. Type Checker: Expected Real, but got False in: r
. Type Checker: Expected Real, but got False in: r
. Type Checker: Expected Real, but got False in: r
. Type Checker: Expected Real, but got False in: r
. Type Checker: Expected Real, but got False in: r
. Type Checker: Expected Real, but got False in: r
. Type Checker: No function domains matched in function application:
Types: (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) (U Real False) (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) (U Real False) -> renderer3d
       (Real Real Real -> Real) Real (U Real False) -> renderer3d
       (Real Real Real -> Real) Real -> renderer3d
Arguments: (Real Real Real -> Real) Real (U Real False) (U Real False) (U Real False) (U Real False) (U Real False) (U Real False)
Expected result: renderer3d
 in: (isosurface3d (λ: ((x : Real) (y : Real) (z : Real)) (let: ((posn : (Vectorof Real) (vector x y z))) (vmag^2 (v- posn ctr.posn)))) (ann (sqr r) Real) (ann (- ctr.x r) (U Real False)) (ann (+ ctr.x r) (U Real False)) (ann (- ctr.y r) (U Real False)) (ann (+ ctr.y r) (U Real False)) (ann (- ctr.z r) (U Real False)) (ann (+ ctr.z r) (U Real False)) #:line-style (quote transparent) #:color color)



On Apr 19, 2014, at 10:46 PM, Greg Hendershott <greghendershott at gmail.com> wrote:

> I think you don't want those #{} annotations in the function definition:
> 
>> (define (sphere3d #:posn #{ctr.posn : (Vectorof Real)} #:r #{r :
>> Nonnegative-Real} #:color [#{color : Plot-Color} "black"])
> 
> The following typechecks OK for me:
> 
> (define (sphere3d #:posn ctr.posn #:r r #:color [color "black"])
> 
> In other words, when you annotate the function using `(: sphere3d
> ___)`, you've told Typed Racket all it needs to know about the
> function type. Then you can write the function definition just as you
> would in untyped Racket.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140419/e4436254/attachment.html>

Posted on the users mailing list.