aabtop / reify

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

Enable Reify struct members to have default values. #16

Open aabtop opened 4 years ago

aabtop commented 4 years ago

This is pretty much essential in reducing verbosity to acceptable levels, especially when more complicated types are introduced and we need to enable more obscure features.

For example, a circle could have a default radius of 1 and a default center of [0, 0], which would make circles instantiable without any parameters.

The hard part of this is deciding how and where to describe the default values. Ideally we would describe them in the same place we define the type, but that is in Haskell, and the implication here is that we'd need to make the codegen system work with values as well as types (and map between them), which is a lot of added complexity. In addition we'll need to write codegen from Haskell values to each different language... It would be nice though if TypeScript could introspect the values resulting from defaults.

Alternatively we could just implement defaults as optional values, and if a value doesn't exist, then it's up to the runtime to decide what that means and e.g. assign defaults. The downside here is that different runtimes may interpret this differently, plus TypeScript wouldn't be able to know what a value gets defaulted to, and there is little support for documenting the defaults.

I think we should make this work somehow with defaults encoded into Haskell, even if it's more difficult. It will enable much easier to generate automatic documentation.