nevalang / neva

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

Sub streams implementation #35

Closed emil14 closed 2 years ago

emil14 commented 2 years ago

Sub streams with support of unlimited nesting allows asynchronously process nested data but they are not implemented and it seems to be very hard to achieve.

Example from FBP book:

 < city1 
     < cust11 detl111 detl112...> 
     < cust12 detl111 detl112...>
  >
  < city2 
     < cust21 detl211 detl122...> 
     < cust22 detl221 detl222...>
  >
  ...

Problems


Related to https://github.com/emil14/fbp-book-ru/blob/main/7_compos.md (sub-streams) and #58

Related to #58


Are staticly typed sub-streams even possible? Imagine a component with sub-stream sensitive inport - where does it takes input? From several different components that we hope sends their data in the right order?

emil14 commented 2 years ago

Don't implement

Sub-streams represents structured data. It's possible to avoid them and use lists, structs, maps

Problems

emil14 commented 2 years ago

Bracket data type

Follow classical FBP and introduce brackets data type

Problems

emil14 commented 2 years ago

Bools

There is already a type with 2 possible values - boolean. Just is it with union type:

F 5 4 3 T F 2 1 0 T -> + -> 3 12

Problems

emil14 commented 2 years ago

Signals

Use one sig as open bracket and two as a closed (or vice versa)

() () 3 3 ()
() () 2 2 ()
  -> + -> 4 6

Problems

emil14 commented 2 years ago

Only flat sub streams

Do not use sub-streams to represent nested structures, use them to represent dynamic lists only

Problems

emil14 commented 2 years ago

Native (struct-based) interfaces

Go has builtin interfaces like Reader or Closer. Brackets might be implemented in a similar way using structures

{ open: bool }

Problems


Gradual typing fix

The following form will make gradual typing problem less likely (although won't solve it completely)

{
  bracket: {}  // <- field and value signaling that message is a bracket
  open: bool
}
emil14 commented 2 years ago

Group-extended struct-based

Modification of a prev variant but with group field. The meaning is that classical FBP's bracket-IPs can contain group-name, see book

{
  group string
  open bool
}

Problems

emil14 commented 2 years ago

Sub-stream defenitions

Just thinking out loud!

Maybe there's a way to have substreams descried staticly just as we have port-types and like we would like to have types? Something like a:

bank-stream:
    branch: 
        type: int
        children: # must be array because there could be stream like (a (b b) (c c))
            - account: 
                type: int
                children:
                    - date:
                        type: int
                    - trans:
                        type: str

Maybe key names even can be ommited somehow?

emil14 commented 2 years ago

Generic struct

Implement StreamItem<T> generic type to operate on streams. This should solve "stream item is data OR bracket" typing problem.

{
  bracket: bool
  open: bool
  data: T | null 
}

Problems