[racket] Immutable vectors

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Thu Sep 5 10:42:02 EDT 2013

Neil Toronto writes:

 > FWIW, `vector->immutable-vector' is pretty fast. It's usually the least 
 > significant part of an O(n) operation. Its two biggest problems are that 
 > it allocates memory and annoys people.

That's a good summary of my first impressions ;-)

 > If you're working in Typed Racket, you might consider using the 
 > `math/array' library. It provides multidimensional arrays with O(1) 

It's on my radar for when I move on to exploring Typed Racket. The
concept looks very interesting, with many idea's from Haskell's REPA,
except that it's in a language I can actually use to do something
useful.

 > to do something similar: have library functions operate on mutable 
 > vectors, with user-facing functions accepting and receiving immutable 
 > vectors, or some more abstract wrapper data type. The `math/matrix' 

That's certainly doable, but it looks like a lot of overhead for using
a very basic data structure.


Scott Klarenbach writes:

 > Check out some of the functional data structures found here:
 > 
 > http://www.ccs.neu.edu/racket/pubs/sfp10-kth.pdf
 > 
 > VLists may be of particular interest in your case.

That's the stuff in the pfds package, right?

  https://pkg.racket-lang.org/info/pfds

Interesting indeed, makes me think of Clojure vectors. And written to
be used as a drop-in replacement for lists. I'll play with that as
well!

The implementation is in Typed Racket as well, so should I expect the
same performance problems as with arrays when I work in plain Racket?

Konrad

Posted on the users mailing list.