nevalang / neva

🌊 Dataflow programming language with static types and implicit parallelism. Compiles to native code and Go
https://nevalang.org
MIT License
85 stars 7 forks source link

Components sensitive to substrams #281

Closed emil14 closed 5 months ago

emil14 commented 1 year ago

I was thinking on https://github.com/nevalang/nevalang/discussions/280 and turns out it's not clear how to implement components that must be aware of sub-streams. Let's think of * component that multiplies numbers. There's several approaches to achieve that:

  1. 2 inports, 1 outport - limited arity (binary), for more than 2 numbers have to chain like in conventional langs
  2. array inports, 1 outport - N-arity but static. Number of inports (of numbers to multiply) must be known at compile-time. Impossible to compute result for dynamic input (dynamic length)
  3. 1 vector (slice) inport, 1 outport - can solve dynamic data but a) we have to create vec for every task and b) not FBP way (vectors is "batch" processing). Note: we omit "regular inport with array type" (not to be confused with "array inport") as they have same problem of "staticness" like array-inport)
  4. 1 sub-stream inport, 1 outport - Can solve dynamic data in a FBP-way but have to create sub-stream for every task

Looks like no.4 is the best (and idiomatic) solution but there are some questions.

What if I have a substream and I want (without breaking its structure) multiply its every element by 2? Not "multiply all of them from left to right and then multiply by 2" but just operate on every sub-stream item (which is BTW usual and important thing) and pass it further? Does FBP bible has the answer? Can we ask GPT?


Note that this question is crucial for stdlib implementation but not the compiler/runtime itself

emil14 commented 1 year ago

Array inports WITH Sub streams

The most generic form of + would be array inport that accepts sub-streams. This way we can some sub-streams from several places. This is also more complicated and there's still a question whether we want to be able to work with non-sub-stream elements at the same time

emil14 commented 1 year ago

Array inports WITH optional Sub streams

To continue https://github.com/nevalang/nevalang/issues/281#issuecomment-1517282027

This (in theory) would allow to "sum all items from this sub-stream plus this non-sub-stream regular number coming from second array inport slot". There are questions ofc:


See #285

emil14 commented 5 months ago

We have task for stdlib design and I don't see a reason to keep this issue open