Open fmap opened 10 years ago
While modifying object prototypes would give us a pretty interface, we'd have to worry about conflicts between libraries. @yorickvp has proposed using ES6 WeakMap
s instead:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap. https://github.com/Benvie/WeakMap.
So I figure we'd be providing each typeclass an extensible map, which given some constructor, returns the appropriate function implementations?
@LeopoldTal How's thinking/coding progressing here?
Proposal: rather than retrieve generics based on values, we could have the interface provide functions for you, whose values change based on arguments.. Typeclasses are instances of a class
Typeclass
, which provides anextend
method, whereby new instances can be appended. When a typeclass' generic receives a value, it looks for an implementation against the defaults and its extensions, , baulking if it can't find one compatible..With this, out concat example could be rewritten: