purescript / purescript-prelude

The PureScript Prelude

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`arrayBind` causes Maximum call stack size exceeded

acple opened this issue · comments

In short,

> import Data.Array
> [1] >>= \_ -> replicate 200000 0
file:///tmp/p/.psci_modules/Control.Bind/foreign.js:5
      Array.prototype.push.apply(result, f(arr[i]));
                           ^

RangeError: Maximum call stack size exceeded
    at file:///tmp/p/.psci_modules/Control.Bind/foreign.js:5:28
    at file:///tmp/p/.psci_modules/$PSCI/index.js:5:74
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)

Node.js v20.5.1

When the return value is just a huge array, RangeError is raised immediately, by passing too many arguments to Array.prototype.push function.
Of course this is very rare case but I think it should not be a purescript limitation.
Do someone know any solutions with minimum performance impact?