What you are asking for, is actually a plain fix
:
cd :: (Monad m) => Int -> Int -> m Int
cd = fix (\f c i -> if i == 0 then return c else f (c+i) (i-1))
This will repeat the computation, until i
becomes 0. (I added c
to have a meaningful computation; but you could assume s=(Int,Int)
with one of them being a rolling sum and the other the counter)
> cd 0 4 :: [Int]
[10]
This is the same as:
relax = fix (\f s -> if isFix s then return s else f (step s))
I believe, this is the definition of iterateUntilM
.