[plt-scheme] Problem writing SML style enumerate vector constructor/initializer in typed-scheme

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Sat Oct 24 17:36:20 EDT 2009

Scott,

It looks like you want build-vector rather than make-vector, for, and set!.

http://docs.plt-scheme.org/reference/vectors.html#(def._((lib._scheme/base..ss)._build-vector))

--Carl

On Sat, Oct 24, 2009 at 5:31 PM, Scott McLoughlin <scott at adrenaline.com> wrote:
> To paraphrase Sarah Silverman's comedy special, "Vectors are Magic."
> While cons cells can be allocated and initialized and chained together
> one at a time, vector memory must be (or should be) allocated as a block
> and then initialized in a nice tight loop.  This creates some problems for
> typed code.
>
> Case in point, I'm trying to implement SML's style enumerate array
> constructor in typed-scheme.
>
> The code is a little messy as I've been trying different things,
> but I think the essential errors  are apparent.
>
> (define: (x) (enumerate [size : Integer] [init : (Integer -> x)]) :
> (Vectorof x)
>   (let: ([v : (Vectorof x) (make-vector size)]) ; <<< big problem
>     (for ([k (in-range size)])                    <<< problem #2 I can't
> seem to grok
>            (vector-set! v k (init k)))))
>
> So the first obvious problem is that make-vector has no obvious
> default value of the type variable x.
>
> The second error is a little more obscure to me and relates to the for
> expression.
>
> Here is DrScheme's error message:
>
> typecheck: untyped identifier in-range imported from module <for.ss> in:
> in-range
> typecheck: Expected (Vectorof x), but got Void in: fold-var
>
> Scott


Posted on the users mailing list.