14
A better future for comprehensions Dave Herman

A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

A better future for comprehensions

Dave Herman

patrick
Text Box
Ecma/TC39/2014/021
Page 2: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

[for  (x  of  y)  if  (p(x))  f(x)]  

(for  (x  of  y)  if  (p(x))  f(x))

Page 3: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

• Parallel JS is moving in the direction of parallel pipelines – a natural fit for comprehensions.

• Three strikes and you refactor!

• LINQ: one comprehension syntax, unbounded number of (user-definable) traversable datatypes.

Page 4: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

let  a  =  for  (x  of  a1)  

                   for  (y  of  a2)  

                       if  (y  >  x)  

                           {  x,  y  };

Page 5: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

let  i  =  for  (x  of  map1.keys())  

                   for  (y  of  map2.keys())  

                       if  (y  >  x)  

                           {  x,  y  };

Page 6: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

let  p  =  for  (x  of  a1.parallel())  

                   for  (y  of  a2.parallel())  

                       if  (y  >  x)  

                           {  x,  y  };

Page 7: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

• The LINQ idea (which is actually the Haskell idea): comprehensions desugar into generic combinators.

• Any datatype that supports those combinators automatically gets to play along.

Page 8: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

• Defer comprehensions from ES6.

• Jafar and I will present an ES7 proposal for generalized comprehensions.

Page 9: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

Generator

Iterator.prototype

.prototype

[[Prototype]]

generator

[[Prototype]]

[[Prototype]] ??

Page 10: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

Iterator.prototype.  

   zip  

   filter  

   map  

   ...

Page 11: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

table.keys().map(...)  

                       .filter(...)  

!

//  versus  

!

import  {  map,  filter  }  from  "itertools";  

filter(map(table.keys(),  ...),  ...);

Page 12: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

(new  Iterator({  

   next()  {  ...  }  

})).map(...)

Page 13: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

5 Jun 14 Resolutions

Page 14: A better future for comprehensions - ECMAScriptarchives.ecma-international.org/2014/TC39/tc39-2014-021.pdf · 2020. 12. 22. · Parallel JS is moving in the direction of . parallel

• Agree to defer comprehensions.

• No future-proofing placeholder objects (can be added later with low compatibility risk).

• May not generalize generator comprehensions since first RHS eagerly evaluated; more work to do.