Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a promise spec for strongly typed languages?

The Promises/A+ spec is excellent to implement promises, but it uses Javascript's weak typing a lot. Is there a spec for Promises that is designed with languages with strong, static typing such as C#?

like image 963
Max Yankov Avatar asked Jul 05 '15 11:07

Max Yankov


1 Answers

Lots of languages have promises, they're a useful and fundamental building block for concurrency. A lot of them have promises built in as part of their base class library.

  • C#'s Task<T>
  • Scala's Future[T]
  • Java 8's CompletableFuture.
  • Python's Future. (Not statically typed though).
  • Haskell's IO a.
  • clojure's promise.
  • Dart's Future<T>.
  • C++'s std::future<T>.

Most other languages have dominant implementations in userland, for example Swift's and Objective-C's Promise with PromiseKit.

I can go on and on, but the pattern is really everywhere. Most languages have it specified in their language specification. JavaScript is unique in how many implementations there are for promises and the fact the specification tells them how to interoperate with each other.

They're not all identical to promises but they all capture the same idea of a future value. Some are much more limited (no monadic chaining) but most are not.

like image 195
Benjamin Gruenbaum Avatar answered Oct 01 '22 23:10

Benjamin Gruenbaum