[plt-scheme] Yet another (I think) hopefully minor typed-scheme problem with Vectorof types

From: Scott McLoughlin (scott at adrenaline.com)
Date: Tue Oct 27 07:36:15 EDT 2009

So I want to copy a polymorphic vector, (Vectorof a). I first try
something like (let ([vcopy (copy-vector vorig)]) ... and find that
there is no such simple copy-vector function.

Instead, we have the (otherwise very) useful function in scheme/base

    vector-copy! dest dest-start src [src-start src-end] -> void?

Unfortunately, in typed scheme with a parametric Vectorof type, there
is no necessary (make-vector size dflt), as a dflt element is not
computable in the general case. 

Hence it is not possible to compute a "dest" argument at all for 
as written in scheme/base.

Anyway, for now I totally cludged (apply vector (vector->list)) which at
least type checked in typed-scheme, but it seems like an unecessary and
expensive cludge.

Much better would be the addition of a simple function:

    (define (a) (vector-copy [src : (Vectorof a)]) : (Vectorof a)

Even *nicer* would be to add optional start/end arguments, allowing for
the computation of subvectors that type check typed-scheme.

     (define (a) (vector-copy [src : (Vectorof a)] [start = 0] [end = 
-1]) : (Vectorof a)

with the [end = -1] argument simply indexing backwards from the end of 
the vector.

Hope that all "type checks" with the typed-scheme crowd.


Posted on the users mailing list.