Geoffrey Irving wrote: > Most imperative operations in numerical code (my own, at least) > involve incremental construction of vectors, sometimes in random > access order. In many cases these arrays aren't modified once they > are created. Currently each location in BitC memory is either > permanently mutable or permanently immutable, which means that an > array constructed using imperative operations must be copied in order > to become immutable. How difficult would it be to relax this > restriction enough to allow the following pattern: > > f : vector int -> () > freeze : mutable 'a -> 'a # with escape restrictions > let a = make-vector 100 0 > for i in range(100): > a[i] = i > f (freeze a)
BitC has a primitive called make-vector (http://bitc-lang.org/docs/bitc/spec.html#7.5.2) which can be used to initialize immutable vectors incrementally. The above initialization can be written using make-vector as: (define (init n:word) n) (define vec (make-vector 100 init)) All elements can be incrementally initialized using different cases in the init function, but there is no reason to actually make the vector mutable. Since the elements of the array (once initialized) will not be modified even during initialization, my thought is that this support should be sufficient? There is currently no equivalent of make-vector for arrays, but one can can be added if necessary. Swaroop. _______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
