Suggestion: Infix operators/functions

Mike Samuel mikesamuel at gmail.com
Fri Feb 2 15:58:33 UTC 2018


How would this affect ASI?

    a  // no semicolon inserted since '+' is an infix operator
    +b

    a  // semicolon inserted since '!' is not an infix operator
    !b

but what about

    function '!'(a, b) { ... }
    // now '!' is both an infix and a prefix operator

    a  // is a semicolon inserted?
    !b






On Fri, Feb 2, 2018 at 6:55 AM, Thomas Grainger <tagrain at gmail.com> 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#iss
> uecomment-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/01465ab8/attachment.html>


More information about the es-discuss mailing list