Re: The Paradox of Partial Parametricity

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