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

From: Scott McLoughlin (scott at adrenaline.com)
Date: Sun Oct 25 00:09:33 EDT 2009

That did it - thanks a million! 

build-vector is sort of an untyped "enumerate" function already built
into Scheme (is it part of the R5RS or R6RS standards?). Pretty cool!!!

Scott

Carl Eastlund wrote:
> 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
>>     
>
>
>   

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

Posted on the users mailing list.