mstade / funkis

Functional JavaScript
MIT License
6 stars 0 forks source link

Deftype #11

Open mstade opened 10 years ago

mstade commented 10 years ago

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.

coveralls commented 10 years ago

Coverage Status

Coverage decreased (-0.58%) when pulling 045031ebc229c32055db54fc55f222d2b1dd8f43 on deftype into 85adb2f7c928810f29234cef8df9d9590bddc5b6 on master.

mstade commented 10 years ago

Well that's nifty tooling, ain't it?

mstade commented 10 years ago

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.

mstade commented 10 years ago

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.

mstade commented 10 years ago

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.

coveralls commented 10 years ago

Coverage Status

Coverage decreased (-1.03%) when pulling f062623277fd59f2a14087e297e5f0d41dc8bf8d on deftype into 85adb2f7c928810f29234cef8df9d9590bddc5b6 on master.

coveralls commented 10 years ago

Coverage Status

Coverage decreased (-1.03%) when pulling f062623277fd59f2a14087e297e5f0d41dc8bf8d on deftype into 85adb2f7c928810f29234cef8df9d9590bddc5b6 on master.