Home Update lets in a monad an unknown number of times. (Template) Haskell
 I want to write code that repeats a few lines in a do block an unknown number of times. Pseudocode example: main = do let x = 0 repeatUntil (x > 50) let y = x let x = y + 1 x -- this should return 51.  Note that it's possible that there are multiple lets that are updated in the repeatUntil body and/or that are being used in the guard. I sadly enough can't really just make a call to some recursive function to which I pass all of my lets as arguments, since the program described above is generated using metaprogramming and it would be a huge pain to make that work (since I don't really keep track of which lets are in the current scope, so I don't know what I have to pass around). In short: (how) can I execute a sequence of statements until a certain expression evaluates to false, where the statements use "variables" that are stored as lets and that are updated by assigning a new value to them? It's important that I don't have to pass all the lets that are in scope to some function, because I don't keep track of what's in the scope, so I don't know what to pass to that function either. Scanning the statement sequence for all used lets in order to know the (relevant part of the) scope is not really feasible either I think. I know that this is a very strange question and that the design of the system is flawed, but I can't easily change that.