-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scope creep #5
Comments
@masaeedu From a category-theoretic perspective, I won't generalize that operator any further than this unless I'm presented with math that tells me that a functor isn't the top of that hierarchy anymore. (And trust me when I say that'd be incredible news all over. Haskell/etc. fans would be groveling out the ears over that. Or in other words, it probably won't happen for quite a while.) As for why I chose to broaden the scope: I was looking to address not only function composition, but also the vast number of reactive operators and other collection-oriented operators that 1. shouldn't need to be so dependent on observables (
Function composition is easy, but I'm trying to see how much of the rest of this I can cover with as little surface area I can, especially with as little new syntax as practically possible, and without succumbing to the serious scope creep that one has. To be more precise, here's what those two address, out of that list:
I personally disagree about some of their decisions (specifically that of making pipelines not simple binary operators), but that's a conversation I've found little success in even attempting to get anywhere with. |
@isiahmeadows The Regarding the pipeline operator, I similarly wish that it would just be reverse partial application rather than a bajillion other overloaded things, but I guess that's a discussion for a different repo. |
I know it's not. More to the point, composition for functions in many more recent functional languages is typically defined for But equivalent ≠ alias, and mathematically, equivalence works well enough. (It's an unusual application, and in an object-oriented language, it works well enough.) As an item of note, Fantasy Land is pursuing strong profunctors (basically, profunctors with the ability to "split") over arrows. const map = (f, g) => x => g(f(x))
const promap = (f, a, b) => x => b(f(a(x)))
const first = f => ([a, b]) => [f(a), b]
I'm aware. But here's my question (it's two-fold):
I know it's possible to implement functors using object factories, much like how OCaml uses module functors to emulate type classes and how the competing Static Land (Fantasy Land offshoot) models its types. However, few libraries would be able to migrate well to it, and several people/groups/companies would find it difficult to move their more object-oriented code bases to it, especially if they're heavy users of Lodash, RxJS, and the like. And to be clear, what's listed in the "Possible expansions" is about as far as I plan to draw the line. (I'm not planning on redesigning JS.)
Yeah...I've already criticized it there elsewhere briefly, but for whatever reason, any future discussion about it got shut down pretty swiftly (which didn't come across as particularly civil for an issue where it wasn't even topical). This is also why I kept it out of this proposal - it was easier to focus on the content rather than the semantic noise. |
@isiahmeadows The different hierarchy in PureScript is interesting, but ultimately I'd be very surprised if they don't special case function composition to a simple monomorphic Regarding how I would implement functors, I'd implement them like this:
Whether this is a good approach remains to be seen, but I'd prefer to have this discussion at the library level rather than prematurely baking all this stuff into the language. It's not even that I dislike the approach to structuring functors you have; it's just that I don't think it's a sensible part of this proposal, and puts the cart way before the horse. Ideally, we'd have one proposal for user-specified infix operators (or infix application of existing identifiers), and we'd be able to deal with all the churn in all these different proposals at the library level rather than prematurely baking everything into the language. The language committee seems to be 👎 on that idea based on previous discussions, so the next best thing is to make each incremental operator do as little as possible, as uncontroversially as possible, while leaving yourself open for future improvements (e.g. an fmap operator that dispatches to composition for functions). |
@masaeedu Mine is pretty minimal to start, and I've been very careful to not complicate it more: // x :> f
function pipe(x, f) {
if (typeof f !== "function") throw new TypeError()
return x[Symbol.lift](f)
} The two eventual additions (one inline in the README, the other in #6) I have are a bit more involved:
|
With custom operators, you have three very major complication points, which make it hard to add into a language without designing the language for it in the first place:
|
(They are not against operator overloading AFAICT, within certain constraints.) |
@isiahmeadows
All of these difficulties only arise if you do not have a dedicated delimiter for infix application. Moreover, all these difficulties have to be dealt with anyway for all the new operators being proposed, except that right now they're being dealt with across language proposal repos and are immutable for all users of JS once you stick them in the language
Custom operators do not require this, although you're free to do it if you want. You can still have reserved operators in the language that are not available for user-redefinition. Conflict is impossible if you have delimited infix application.
I don't understand how this is relevant. See above. |
@masaeedu I'd suggest talking to an actual TC39 rep about custom operators, since they would have a better idea what exactly what issues would likely block/inhibit custom operators. |
BTW, I've done a pretty large update to both the formatting and proposal content, including a ton of just explanatory content. Specifically, about the proposal itself:
The major edits beyond above added practically nothing besides prose and clarity, however. The "possible additions" section now only have two entries:
Most everything else is either already factored in or is something I'd likely reject as out of scope. My end goal is to bring the useful bits of Fantasy Land and other similar specs/utilities (like the old observable spec, Promises/A+, the ES iteration protocol), and create something that's easy to use and easy to implement. As for why I let it evolve past function composition? That particular concept is narrow enough it's like putting a bandaid where we already have people making oversized ones for us (Lodash's Expanding it to encompass collections and pseudo-collections more broadly also enabled me to take a second stab at this problem, in a much simpler, less intrusive way. (90% of that functionality is wrapped into In case you're curious what the proposal entails, I have basically a cliffs' notes section at the top, if you just want it at a glance. (I added that since the extensive prose kind of obscures the not-so-large scale of the core of the proposal. 90% of the code implementing it would be over the library additions, not the core syntax.) |
Is there a way to try this in |
@babakness Not currently, but I'm not a heavy Babel user (I'd more likely just fork Acorn or Esprima to try it). If you feel strongly enough about it, please file a separate issue, since this one is about completely different concerns. |
I may be misunderstanding the proposal, but I don't understand why you need the ability to do
[] :> f
orPromise.resolve(x) :> f
or the other@@lift
operations defined in there. I guess it's a good idea to use symbols to keep implementation flexible, but I think the actual proposal should be restricted to function composition to keep things simple and avoid mental overhead.The more things the operator can do the more you need to squint at every member in a pipeline to understand the exact semantics.
As I said, I may be misunderstanding the proposal, happy to be corrected if so.
The text was updated successfully, but these errors were encountered: