koka-lang / koka

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

Effectful vector initialization #391

Closed chtenb closed 6 months ago

chtenb commented 6 months ago

The current vector-init implementation does not allow effects, and thus the following does not compile.

val new-vector = vector-init(10, fn(_) ref(Nothing))

Note that the following is not an alternative, since that will only make one ref object and put it in every spot.

val new-vector = vector(10, ref(Nothing))

The following is currently possible, but it is not as efficient.

fun vector-init-e(n : int, g : int -> e a) : e vector<a>
  list(0, n - 1).map(g).vector
TimWhiting commented 6 months ago

This will be fixed in the next release (currently fixed on the dev branch)

TimWhiting commented 6 months ago

This is released!