Deterministic Proposal

Andreas Rossberg rossberg at
Wed Jun 21 16:36:22 UTC 2017

On 21 June 2017 at 00:58, Guy Ellis <wildfiction at> wrote:

> I have an idea rattling around that allowing the developer to mark a
> function as deterministic would allow the compiler to determine if a
> speed/memory memoization trade-off will improve performance.
> Possible syntax:
> deterministic function sum(a, b) { return a + b; }
> Use case:
> I can only think of one right now: compiler memoization

You probably mean "pure", not "deterministic", which has nothing to do with
this. However, JavaScript is far, far too impure for any such annotation to
ever make sense or enable any sort of memoization. Consider

let i = 0
let o = {valueOf() {return i++}}
sum(o, 0)
sum(o, 0)

 On 21 June 2017 at 17:34, Isiah Meadows <isiahmeadows at> wrote:

> I'd like to note that even Haskell compilers (which can check for this
> trivially) never memoize implicitly. They only memoize infinite data
> structures.
> [...]
> The only time I have found memoization to be very useful is in one
> specific case: lazy evaluation (run once). But that is constrained to
> just evaluating a thunk and storing the result.

I think you are confused. Laziness and memoization are different
mechanisms. And neither takes the finiteness of a data structure into
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list