I wanted to try a mental experiment of creating a stateful function by using only pure ones, without using any sorts of assignment/monads and such. For instance, a function resembling a RS-flipflop, which has Set and Reset inputs:
ff(1,0) -> 1 ; SET
ff(0,0) -> 1 ; just output current state
ff(0,1) -> 0 ; RESET
ff(0,0) -> 0 ; whoops, a side-effect!
In electronics such a flipflop (or any stateful circuit) is implemented by sending output of a circuit back to the input, i.e:
So, I am thinking that some sort of recursion of functions can create stateful functions, right? But how to handle the thing, that it will be infinite?