PureScript FFI ↔ JavaScript Promises: Automatic Conversion?
0 reputation · 05 Nov 2021, 09:14 UTC
Goal
We want a seamless way to call a JavaScript function that returns a Promise from PureScript, automatically mapping it to PureScript’s Effect or Async monad.
Current Constraints
The foreign import syntax treats imported values as raw JavaScript, so a Promise returned by the imported function is passed through untouched. There is no automatic conversion; developers must wrap the Promise manually with Effect.async or Async.fromEffect, adding boilerplate and error handling concerns. This lack of a unified strategy leads to inconsistent patterns across codebases.
Unresolved Decision
Should the FFI layer provide an automatic mapping of Promise-returning functions to Async (or Effect), or should it continue to expose raw Promises and leave conversion to the developer?
- What are the trade‑offs of automatic conversion for type safety and error propagation?
- How would a future FFI change affect existing code that already wraps Promises manually?
- Could a type‑class or annotation be introduced to signal Promise conversion without breaking backward compatibility?