@@ -298,30 +298,62 @@ specific details about the proposal.
298
298
299
299
## Relationship to similar features
300
300
301
- ### Haskell-style typeclasses
301
+ ### Haskell type classes
302
302
303
- TODO
303
+ This proposal was strongly inspired by Haskell's type classes. The conceptual
304
+ model is identical aside from the fact that in Haskell the type class instance
305
+ (essentially an implicit record) is resolved automatically by the type checker.
306
+ For a more Haskell-like calling pattern, one can define functions like
307
+
308
+ ``` js
309
+ function fmap (fn ) {
310
+ return function (functor ) {
311
+ return functor[Functor .fmap ](fn);
312
+ };
313
+ }
314
+ ```
315
+
316
+ Similar to how each type in Haskell may only have a single implementation of
317
+ each type class (newtypes are used as a workaround), each class in JavaScript
318
+ may only have a single implementation of each interface.
319
+
320
+ Haskell type classes exist only at the type level and not the term level, so they
321
+ cannot be passed around as first class values, and any abstraction over them must
322
+ be done through type-level programming mechanisms. The interfaces in this proposal
323
+ are themselves values which may be passed around as first class citizens.
304
324
305
325
### Rust traits
306
326
307
- TODO
327
+ Rust traits are very similar to Haskell type classes. Rust traits have
328
+ restrictions on implementations for built-in data structures; no such
329
+ restriction exists with this proposal. The ` implements ` operator in this
330
+ proposal would be useful in manually guarding a function in a way that Rust's
331
+ trait bounds do. Default methods in Rust traits are equivalent to what we've
332
+ called methods in this proposal.
308
333
309
- ### Java-style interfaces
334
+ ### Java interfaces
310
335
311
336
TODO
312
337
313
- ### Ruby-style mixins
338
+ ### Ruby mixins
314
339
315
340
TODO
316
341
317
342
### ECMAScript ` mixin(...) ` pattern
318
343
319
344
``` js
320
- class A extends mixin (FeatureA, FeatureB) {}
345
+ class A extends mixin (SuperClass, FeatureA, FeatureB) {}
321
346
```
322
347
323
- TODO
348
+ This mixin pattern usually ends up creating one or more intermediate prototype
349
+ objects which sit between the class and its superclass on the prototype chain.
350
+ In contrast, this proposal works by copying the inherited interface methods
351
+ into the class or its prototype. This proposal is also built entirely off of
352
+ Symbol-named properties, but doing so using existing mechanisms would be
353
+ tedious and difficult to do properly. For an example of the complexity involved
354
+ in doing it properly, see the output of the sweet.js implementation.
355
+
324
356
325
- ### ECMAScript proposed bind ( ` :: ` ) operator
357
+ ## Links to previous related discussions/strawmen
326
358
327
359
TODO
0 commit comments