aabtop / reify

Reify lets you embed a customized TypeScript runtime within a C++ application.
MIT License
6 stars 0 forks source link

Support the "function" type in Reify. #14

Open aabtop opened 4 years ago

aabtop commented 4 years ago

This would enable us to communicate with functions as objects back and forth between C++ and TypeScript.

There's a few complicating factors here though, the biggest one being that this does not translate very well to different backends. In other words, so far all of our types represent abstract data that can be serialized to almost any format. As soon as functions are introduced, a type that references a function could no longer be serialized to JSON for example because it really depends a lot on the runtime. A function object is really really tied to the runtime environment, so it would be a relatively "non-pure" data object in that sense. Of course, if a certain serialization mechanism does not support functions, it can always raise an error, but it's still less elegant.

That said, it would be a hugely powerful object to be able to express. It would effectively enable monads in Reify in that by returning a function to host C++, it can act as a continuation to perform more computation after I/O has been performed. It can also enable lazy evaluation.

This would certainly require support for function parameters ( #12 ) as a prerequisite.