W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2013

Re: The Paradox of Partial Parametricity

From: Mark S. Miller <erights@google.com>
Date: Fri, 10 May 2013 06:05:16 -0700
Message-ID: <CABHxS9gKKJ4BpkckM=2_7y8dNwAxUj-nyW9rdWbzvDics28jsQ@mail.gmail.com>
To: Jonas Sicking <jonas@sicking.cc>
Cc: "Tab Atkins, Jr." <jackalmage@gmail.com>, Domenic Denicola <domenic@domenicdenicola.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>, es-discuss <es-discuss@mozilla.org>
On Fri, May 10, 2013 at 5:55 AM, Mark S. Miller <erights@google.com> wrote:
[...]

> This same abstraction in a Q-like promise system would be written
>>
>>     class AsyncTable<t,u> {
>>         constructor() {
>>             this.m = Map<t,u>(); // encapsulation doesn't matter for this
>> example
>>         }
>>         set(keyP :Promise<t>, val :u) {
>>             keyP.then(key => { this.m.set(key, val) });
>>         }
>>         get(keyP :Promise<t>) :Promise<u> {
>>             return keyP.then(key => this.m.get(key));
>>         }
>>     }
>>
>

Actually, it's even better:


     class AsyncTable<t,u> {
         constructor() {
             this.m = Map<t,u>(); // encapsulation doesn't matter for this
example
         }
         set(keyP :Promise<t>, val :Ref<u>) {
             keyP.then(key => { this.m.set(key, val) });
         }
         get(keyP :Promise<t>) :Promise<u> {
             return keyP.then(key => this.m.get(key));
         }
     }


-- 
    Cheers,
    --MarkM
Received on Friday, 10 May 2013 13:05:44 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:49 UTC