Open mstade opened 10 years ago
Well that's nifty tooling, ain't it?
Design note: do not implement internal mutable state for methods and get/set accessors. This is too much of a foot-gun to be useful, and instead any mutability should probably be opt-in and encapsulated on a field-by-field basis; i.e. mutable fields get their own internal state, separate an unreachable from all other fields (unless the field explicitly returns this
.)
Methods and get/set accessors should probably be bound to the type instance, but only if that instance is fully immutable – that is, not only are fields immutable, but the object is closed for extensions as well. Otherwise, this is a bit too much rope as well.
Ditch types in favor of tags. Tags should work somewhat like Clojure's derive
. The idea is that by creating a tag, which is just a name (NB: there is considerable overlap wi ES6 symbols here) you can use that to link things to semantics. More work should be done on the rationale behind this, but I like it and it nicely separates the concern of semantics from these types that are really just sugar around structural validation.
Reopening this since there's a ton of useful stuff on the branch. However, ditch deftype
still, or extract that work into another branch if there's any reason to keep tinkering with it.
Type definitions in JavaScript is a mess. This branch is an effort to come up with some sort of semantic typing, where relationships between objects can be defined by leveraging JS's prototypes.
These are not an effort to implement classes.