State Machines in Programming
Comments discuss modeling software systems, processes, and even brains as state machines, along with various implementation techniques like recursive functions, tail calls, and transition functions in different programming languages.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Eh, just write a state machine.
Not OP, but in functional languages, state machines are often simply a function (State, Input) -> State
It's all just one big state machine.
It still is an amazing state machine.
That just means that the actual state machine has intermediate states for each transition.
direct link to image visualizing the complexity of the state machine required: https://i.stack.imgur.com/SrUwP.png
Yep, the "stateless" part of the state machine is its transition function.
You can implement state machines as a set of mutually-recursive functions with one state = one function. Works very well, is tail-recursive and not trivially replaced by loops.
Sure but now you can't really drive the state machine can you? The state machine has to drive you and provide callbacks for state transitions, something like that.edit: ah I see you'd extract the entire manipulation in a function which would return a terminal type or union thereof, yeah that'd work I guess.
State machines can often be implemented with a set of functions that each handle a single state and then tail-call into the function for the next state.