Basically arrow machine:
newtype Auto ab = Auto (a -> (b, Auto ab))
In Haskell, it is not possible to replace a function on its own, but the machine arrow is a function that returns a new version of itself along with the result:
switcher :: Bool -> Auto Bool Bool switcher x = Auto $ \y -> (x, switcher $ if y then not x else x)
The useful thing about the arrow of an automaton is that it is an arrow, so the Category instance allows you to create such functions. There is also a very useful applicative example.
Side Note: This is the foundation of functional reactive arrow programming (AFRP).
ertes source share