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
acurrently at that index. - The user then gets to provide a new value of type
a, and a new seed.
- The array constructor begins by announcing the current seed value of type