Interestingly enough, I had this same question while trying to translate the Power series, power serious lazy sequence technique into OCaml. I expected to get a magic speedup switching coefficient representation from bare Seq.t
to the memoized variant, but it did not perform anywhere near how I expected (or even in the same ballpark as a naive Haskell implementation). I assumed I just had some perf bug somewhere (which may still be the case), but now I wonder how much that can be attributed to Seq memoization.
I’m still curious about what the expected memory retention is in any case. If you do not retain references to the head of a memoized Seq.t
, is it at least in theory eligible for collection? In particular, I’m trying to understand this comment and why it would even be possible for a tail to retain a reference to some “earlier” head (unless your generating closure was cyclic).