So as to understand the fix
function, from Control.Monad.State
, fix :: (a -> a) -> a
, I have this little code in modifyValue
, that increments an integer until 49, then the function always returns 50.
import Control.Monad.State
type StateVal = Int
modifyValue :: StateVal -> StateVal
modifyValue v | v < 50 = v + 1
modifyValue v = 50
simpleStateStep :: State StateVal ()
simpleStateStep = do
s <- get
put $ modifyValue s
main = do
putStrLn $ show $ fix modifyValue
However when I launch this code, instead of finding the fix point at 50, where the sequence converge to 50... it claims *** Exception: <<loop>>
It is clear that I mistake something since I do not provide an initial state to start the sequence, for example with 1, that would generate [2,3,4,..,49,50,50,50,50....]
Am I using the fix function inappropriately ? Is there something to do so as it can find the fix point 50 ?