[ALGOM-5] continuation monad can easily overflow stack Created: 10/Sep/12 Updated: 10/Sep/12 |
|
| Status: | Open |
| Project: | algo.monads |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Defect | Priority: | Minor |
| Reporter: | ben wolfson | Assignee: | Konrad Hinsen |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
The continuation monad uses tail calls, and because they aren't optimized out it's vulnerable to stack overflows for large computations: ;; there is a function clojure.algo.monads/m-reduce, but it has a (defn add [s] (add (range 1 10000)) ;; stack overflow Can be worked around with a trampoline: (defmonad cont-tramp-m (defn call-cc-tramp [f] (defn run-cont-tramp [cont] (defn add2 [s] (add2 (range 1 1000000)) ;; -> 1 |
| Comments |
| Comment by ben wolfson [ 10/Sep/12 12:01 PM ] |
|
I neglected to include m-result-cont and m-bind-cont for the cont-tramp-m call! (defn m-result-cont [v] (fn [c] [c v ::cont])) (defn m-bind-cont [mv f] (fn [c] [mv (fn [v] [(f v) c ::cont ]) ::cont])) |