I want to write a calculation expression in F # that can repeat the operation if it throws an exception. My code now looks like this:
let x = retry (fun() -> GetResourceX())
let y = retry (fun() -> GetResourceY())
let z = retry (fun() -> DoThis(x, y))
etc. (this is obviously an astract representation of the actual code)
I need to be able to repeat each function a certain number of times, which I defined in elswhere.
I thought a calculation expression could help me here, but I don't see how this could help me explicitly remove each right side in Retryable <'T>
I could see a calculation expression that looked something like this:
let! x = Retryable( fun() -> GetResourceX())
etc.
I understand that Monads, in a crude way, are types of wrappers, but I was hoping for that. I know that I can overload the operator and have very concise syntax for converting the operation to Retryable <'T>, but for me it just makes the repeat / wrap more compressed; he is still there. I could wrap each function as Retryable <'T>, but once again, I donβt see a value over what was being done at the top of the message (the retry call on each operation is at least very explicit).
Maybe the computation expressions are a wrong abstraction here, I'm not sure. Any ideas on what you can do here?
source
share