Open pchiusano opened 4 years ago
This looks like a good one. I like that you can get both the zippy and cartesian-producty version from the same API: http://blog.ezyang.com/2020/01/vmap-in-haskell/
And here's a zippy ability: https://gist.github.com/pchiusano/f12d1ebdf1e4396fb1e311ad460ec9a8
Related to #1055 and some inspiration from @ekmett - Ed if you are reading this, would like to hear your latest thinking / links to more reading for this sort of thing.
This is an idea I'm interested in exploring for writing high performance vectorized code in Unison in what looks like a straightforward scalar style. Assume we have a type,
Vec a
, which denotes a(Set Nat, Nat -> Maybe a)
, basically a subset of indices and a way of grabbing the value at any index. It's implementation would be something super efficient, backed by unboxed, packed vectors. API sketch:You could write code directly with this and it would all be efficient unboxed operations with loops happening on the Haskell side hopefully using SIMD rather than in pure Unison.
Now assume we have an
ability Vectorized
, which lets us write straightforward-looking scalar code:The idea here is that the
vectorize
is a builtin function which has a special handler. The handler actually inspects the continuation, peels off the head operation of that continuation, and lifts it to operate onVec
. In this case, the continuation isn -> n + 1
, which the runtime converts to a call toVec.nat.increment
rather than doing the loop in pure Unison.