Open mlhaufe opened 1 year ago
The parameterized recursive form will cause an issue with strict equality tests:
const NumListData1 = ListData(Number),
NumListData2 = ListData(Number)
NumListData1 !== NumListData2
const ListData = memofix((T) => {
const _ListData = data({ of: T }),
Nil = data(_ListData, {}),
Cons = data(_ListData, { head: T, tail: ListData(T) })
return _ListData
})
To derive a general solution I don't see how the splitting out of data
to one per class helps. The recursive form implies that an owning object needs to be returned. Add that to the requirement of a [children]
reference and it looks like we've come full-circle back to a factory-like object. abstracting the memofix form and generalizing for the family looks exactly like the original data
decl with a semantic distinction that doesn't seem to make much of a difference...
The Enumeration class pattern seems to be a reasonable counter-point:
data
currently defines a class hierarchy as well as a factory for constructing instances of that hierarchy:This requires extra effort in type checking, complection, and declaration (due to the fixpoint requirement).
If
data
did not declare a factory then the above forms can be represented as:The syntactic burden is comparable to the original forms except for the parameterized recursive form.
For
complect
to work as desired, eachdata
declaration has a[children]
symbol that returns the extensions:Which enables:
This should have the added benefit of making type declarations easier as they are non-trivial in typescript and very challenging to express in jsdoc.