[racket] typing a function
Hello,
can someone explain me the error I get for this function, and how to fix it?
Thanks in advance.
========
#lang typed/racket
(define-type (Array a) (Rec AA (U (Vectorof a) (Vectorof AA))))
(: make-array (All (a) ((Listof Positive-Index) a -> (Array a))))
(define (make-array dims init)
(let loop ((dims dims))
(match dims
((list first)
(make-vector first init))
((list-rest first rest)
(let ((v (make-vector first)))
(for ((i (in-range first)))
(vector-set! v i (loop rest)))
v)))))
========
Welcome to DrRacket, version 5.3 [3m].
Language: typed/racket [custom]; memory limit: 128 MB.
. Type Checker: Polymorphic function vector-set! could not be applied
to arguments:
Argument 1:
Expected: (Vectorof a)
Given: (Vectorof Integer)
Argument 2:
Expected: Integer
Given: Integer
Argument 3:
Expected: a
Given: (Rec AA (U (Vectorof a) (Vectorof AA)))
Result type: Void
Expected result: Any
in: (vector-set! v i (loop rest))
. Type Checker: Expected (Rec AA (U (Vectorof a) (Vectorof AA))), but
got (Vectorof Integer) in: v
. Type Checker: Summary: 2 errors encountered in:
(vector-set! v i (loop rest))
v
>