12345678910111213141516171819202122232425(* Higher-order operator to apply a stream of stream functions *)openZtypestype'amem={mutablem:'a}type'ainstance=I:{s:'s;t:'s->'a}->'ainstance(* [irun(f, x)] takes two streams [f : 'a -D-> 'b] and [x: 'a] *)(* and computes [f(0)(x)] *)letirun=letalloc()={m=None}inletstepself(f,x)=letI{s;t}=matchself.mwith|None->letNode{alloc;step;reset}=finlets=alloc()inresets;letv=I{s=s;t=step}inself.m<-Some(v);v|Some(s)->sintsxinletresetself=self.m<-NoneinNode{alloc=alloc;step=step;reset=reset}