Introduction forms for immutable arrays [00GM]

After mentioning it in last week's weeknotes, I got some great feedback from Verity on an introduction form for immutable arrays. (Again, the biggest constraint here is that we don't want to use lists: Swarm does have lists, but not built-in in a primitive way. Using lists requires you to first unlock algebraic data types as well as recursive types, and you should be able to unlock and use arrays independently.)

After a bit of back and forth, the current best idea is

(Int -> a) -> b -> (b -> Unit + Int * (a -> (a * b))) -> Array a
  • The first argument specifies the starting value at any index.
  • The second argument is a seed value for the unfold.
  • I like to think of the third argument as a protocol for communication between the array constructor and the user, specifying the process for a sort of imperative unfold.
    • The array constructor begins by announcing the current seed value of type b.
    • The user gets to choose whether to stop, or to continue by specifying an index.
    • The array constructor provides the value of type a currently at that index.
    • The user then gets to provide a new value of type a, and a new seed.
This is trickier to implement than what I had before (e.g. it requires several new types of CESK machine continuation frames instead of just one, and in practice, we want to wait until we see which indices are requested before deciding on the final size of the array and filling in any missing values), but ultimately should be fine. I need to finish up the implementation and play around with it: implement some other simpler introduction forms in terms of it, and try using it for things that were inefficient before.