Closed anfelor closed 5 months ago
Ah, we would need an if yielding check in the hand written c code for this.
Also since vectors don't have copy on write semantics I don't think it is advisable to be using control effects in general with this API. We should probably document better how vectors should be used and what to consider. But we probably should allow for exceptions.
I'm wondering whether this would be an appropriate solution @daanx:
// Create a new vector of length `n` with initial elements given by function `f` .
pub fun vector-init( ^n : int, f : int -> e a ) : e vector<a>
val v = unsafe-vector(n)
forz( 0.ssize_t, n.ssize_t ) fn(i)
unsafe-assign(v,i,f(i.int))
v
Thanks so much! Fixed now.
In #388, the
vector-init
function was changed to allow an arbitrary effect on the initialization function. While this is a welcome change for most effects, it does not play well with control effects. Consider the following program:The expected behaviour is that
test-vector
should return2^5
vectors of length5
(containing all possible combinations ofTrue
andFalse
elements in a 5-element vector) -- just like thetest-list
function returns the corresponding lists. But in Koka 2.6.0,test-vector
only returns two zero-element vectors.