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
The problem with your Haskell code is, that type
only introduces a synonym, which is quite similar to what typedef
in C does. One important restriction is, that the expansion of the type must be finite, you can't give a finite expansion of your state machine. A solution is using a newtype
: A newtype
is a wrapper that does only exist for the type checker; there is absolutely zero overhead (excluded stuff that occurs because of generalization that can't be removed). Here is your signature; it typechecks:
newtype FN = FN { unFM :: (IO FN) }
Please note, that whenever you want to use an FN
, you have to unpack it first using unFN
. Whenever you return a new function, use FN
to pack it.