data currently defines a class hierarchy as well as a factory for constructing instances of that hierarchy:
const colorData = data({ Red: {}, Green: {}, Blue: {} })
const PointData = data({
Point2: {x: Number, y: Number},
Point3: {x: Number, y: Number, z: Number}
})
const PeanoData = data(() => ({
Zero: {},
Succ: {pred: PeanoData}
}))
const ListData = data((T) => ({
Nil: {},
Cons: {head: T, tail: ListData(T) }
}))
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:
const ColorData = data({}),
Red = data(ColorData, {}),
Green = data(ColorData, {})
const PointData = data({}),
Point2 = data(PointData, {x: Number, y: Number}),
Point3 = data(PointData, {x: Number, y: Number})
const PeanoData = data({}),
Zero = data(PeanoData, {}),
Succ = data(PeanoData, {pred: PeanoData})
const ListData = (T) => {
const ListData = data({ of: T }),
Nil = data(ListData, {}),
Cons = data(ListData, { head: T, tail: ListData })
return List
}
The syntactic burden is comparable to the original forms except for the parameterized recursive form.
For complect to work as desired, each data declaration has a [children] symbol that returns the extensions:
Peano[children] // [Zero, Succ]
Which enables:
const Peano = complect(PeanoData, [...])
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.
datacurrently 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
datadid 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
complectto work as desired, eachdatadeclaration 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.