Basically, my problem is that I'm trying to compose a very large number of functions, so I'm creating a deep chain of composed functions. Here is my code:
let rec fn (f : (State -> State option) -> (State -> State option)) (n : int) acc =
match n with
| 0 -> acc
| _ -> fn f (n - 1) (f << acc)
and I make a call to it:
let foo = fn id 10000000 id bottom
So, it does ten milion iteration and it should combining lots of functions.
I know for sure that fn is tail recursive (at least, I hope so), but the execution goes stack overflow and I can't figure out why.
At this point, the problem should be the deep cobination. So I was hoping for suggestions, tips, everything.