Andreas Rossberg (2014-01-28T23:27:55.000Z)
domenic at domenicdenicola.com (2014-02-04T16:10:56.607Z)
On 28 January 2014 21:21, Quildreen Motta <quildreen at gmail.com> wrote: > ``` > Promise.then :: (Promise(a)) => ((a → MaybePromise(b), (a → MaybePromise(b)) > Promise.then :: (Promise(Promise(a))) => ((a → MaybePromise(b), (a → MaybePromise(b)) > ``` This type is not really accurate. Due to recursive unwrapping, `then' has no type you could express in any reasonable type system -- the argument type can be an arbitrary tower of nested promises (and the maximum one for each use). As you note below, this makes the operation inherently non-parametric. (Which is why I still hold up that recursive unwrapping is a bad idea, especially as the core primitive.) > But later, once `flatMap` is introduced, you'll be able to deal with nested > promises without breaking parametricity: > > ``` > Promise.flatMap :: (Promise(a)) => (a → Promise(b)) > ``` > > If that's correct, I don't see any use cases for Promise.resolve right now, > unless a library where to provide a corresponding unspecified `flatMap` > implementation. The V8 implementation provides it under the name `chain', with the obvious semantics.