fluencelabs / aqua

Programming language for distributed systems & p2p
https://fluence.dev/docs/aqua-book/introduction
GNU Affero General Public License v3.0
154 stars 24 forks source link

Add PushToStreamExpr #209

Closed alari closed 3 years ago

alari commented 3 years ago

Pushing value to a stream is a very common pattern, used for conditional returns and aggregation.

Currently, the only way to push a value to a stream is via a function call. But functions have strict types, so to keep the type checker happy we need to make a new function with proper types every time. It makes the code very cumbersome.

In the future, we should use (co)functors and (call profunctor optics to fix that better way: with no function execution, keeping the tetraplets untouched. Yet to do that, this pattern should be well identified in the code.

The proposition is to add custom syntax for pushing a value into a stream:

-- It must be a stream, defined in the scope
stream: *u32
-- Push a value into the stream: value may be a literal, a variable, constant, whatever
stream <<- value

Now it can be compiled with Op.identity. Later we will optimize with (apply or some other advanced AIR syntax.

Related to #200, #187

folex commented 3 years ago

Now it can be compiled with Op.identity

Then tetraplets would change silently 🤔