quangis / transforge

Describe processes as type transformations, with inference that supports subtypes and parametric polymorphism. Create and query corresponding transformation graphs.
GNU General Public License v3.0
2 stars 0 forks source link

Hide scope from user via decorators #68

Closed nsbgn closed 2 years ago

nsbgn commented 2 years ago

The recommended way of defining a language either via scope:

A = TypeOperator()
cct = Language(scope=locals())

... or via properties:

cct = Language()
cct.A = TypeOperator()

... both have issues. You need to remember to define the namespace only after you've defined everything else. In the first, there's loose wiring in the use of locals(); in the second, you need to be very verbose, referencing the Language in every definition and in every typing.

Using decorators would solve this:

@Language
def cct():
    A = TypeOperator()
    ...
nsbgn commented 2 years ago

Alternatively (or additionally), whole modules could be passed as scope. You could do cct = Language(cct.vocab)