koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.16k stars 151 forks source link

Unique vectors #550

Open TimWhiting opened 3 weeks ago

TimWhiting commented 3 weeks ago

Addresses #544

@anfelor can you take a look at this?

I added a few public apis and a few private helpers. Public:

The most important function is the copy function, which ensures that the vector is unique prior to applying any mutation operations. For many cases we would expect it to be unique.

TimWhiting commented 3 weeks ago

We might want to add a few more apis (cutting an array short and dropping the the rest of the array), or extending an array.

anfelor commented 1 week ago

We might want to add a few more apis (cutting an array short and dropping the the rest of the array), or extending an array.

Yes, that would be fun! I think we could also support vector.filter, which would require us to write box_null into the tail of the vector and keep a separate length field. In OCaml, this is unsupported since box_null might not be an inhabitant of the type of the elements though, and I wonder if there is a problem that I don't see currently.

TimWhiting commented 1 week ago

We might want to add a few more apis (cutting an array short and dropping the the rest of the array), or extending an array.

Yes, that would be fun! I think we could also support vector.filter, which would require us to write box_null into the tail of the vector and keep a separate length field. In OCaml, this is unsupported since box_null might not be an inhabitant of the type of the elements though, and I wonder if there is a problem that I don't see currently.

I think these sorts of APIs are maybe best left to a resizeable vector type, which could hold on to the length like you mention and have a resize policy for add / extending the vector as well. What do you think?