Monad computation does not work with TryWith as expected when used with Result
See original GitHub issueDescription
My logic here is that computation expressions should not deviate from universal concepts as that would surprise and confuse users. A try...with
operation should always handle exceptions and not propagate them (in other words it should behave similarly to the try...with
expression outside of a computation expression).
The monad.strict
works as expected in this case, but monad
does not.
Repro steps
let r : Result<unit, Exception> = monad {
try
failwith "oops"
return ()
with exn -> return! Error exn
}
Expected behavior
Error
Actual behavior
Exception
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Weird try/with/finally behavior in monad CE · Issue #137
wallymathieu mentioned this issue on Aug 30, 2020. Monad computation does not work with TryWith as expected when used with Result #346.
Read more >f# - Wrangling TryWith in Computation expressions
My problem is here: I'd like to be able to catch any failure in the 'combining' function and return a failure, but it...
Read more >Exception vs Result - Learning
It means that you have to be careful what code you put between the “try-with” and the demand for the backtrace, but it's...
Read more >F#: Delayed, Compositional Maybe Monad (Workflow)
If the Delay function evaluates expr then the monad does not support delayed execution and the value is immediately available. Similarly, if Run ......
Read more >Adding try-with-resource to Scala
Monads do not seem to fit the idea because they represent just dependent calculations, so there will be nothing to call at the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Seems unintentional.
Reopening the issue as I think it could be fixed independently without a whole redesign.
See #347
If you try your code with this fix, you’ll get a compilation error with a message explaining exactly what to do.