Suggestion: Infix operators/functions
Isiah Meadows
isiahmeadows at gmail.com
Fri Feb 2 12:19:58 UTC 2018
As it stands, I'd rather see operator overloading before custom operators.
In order to have decent custom operators, you really have to take into
account the whole grammar, and adding them in a way that's not a blatant
tack on usually involves rethinking the entire grammar. In contrast,
operator overloading only requires a rethink of the primitive object model,
and only analogous to how `instanceof` had to change to accommodate
`Symbol.hasInstance`.
On Fri, Feb 2, 2018, 07:07 kdex <kdex at kdex.de> wrote:
> In ECMAScript's current state, infix operators would likely complicate
> future
> discussions of operator overloading. Before we tackle these problems, I
> think
> it's more convenient to have type annotations first.
>
> On Friday, February 2, 2018 12:55:17 PM CET Thomas Grainger wrote:
> > I'm porting this from the TypeScript issue tracker, original from:
> > https://github.com/Microsoft/TypeScript/issues/2319#issue-60851953
> >
> > Since it's very unlikely that the extension methods will ever be
> > implemented [in a call-site-rewrite
> > manner](https://github.com/Microsoft/TypeScript/issues/9#
> > issuecomment-74302592),
> > please consider adding infix operators to enable writing in functional
> > style similarly to what can be done in Haskell:
> >
> > Monoids
> >
> > ```js
> >
> > function '+' (left, right) {
> > return left.concat(right);
> > }
> >
> > [1, 2, 3] '+' [4, 5]; // [1, 2, 3, 4, 5]
> >
> > ```
> >
> > Monads
> >
> > ```js
> > function '>>=' (promise, bind) {
> > return promise.then(bind);
> > }
> > $.get('/get') '>>=' x => $.post('/save', x + 1)
> > ```
> >
> > Functors
> >
> > ```js
> > function '.' (inner, outer) {
> > return function(value: a) : c {
> > return outer(inner(value))
> > }
> > }
> >
> > function f(x) { }
> > function g(y) { }
> > (f '.' g)(x); // z
> > ```
> >
> >
> >
> > Thomas Grainger_______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180202/c18e314d/attachment.html>
More information about the es-discuss
mailing list