I implemented a simple state machine in Python:
import time
def a():
print \"a()\"
return b
def b():
print \"b()\"
return c
def c():
print
In Haskell, the idiom for this is just to go ahead and execute the next state:
type StateMachine = IO ()
a, b, c :: StateMachine
a = print "a()" >> b
b = print "b()" >> c
c = print "c()" >> a
You need not worry that this will overflow a stack or anything like that. If you insist on having states, then you should make the data type more explicit:
data PossibleStates = A | B | C
type StateMachine = PossibleStates -> IO PossibleStates
machine A = print "a()" >> return B
machine B = print "b()" >> return C
machine C = print "c()" >> return A
You can then get compiler warnings about any StateMachine
that forgot some states.