question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Monad computation does not work with TryWith as expected when used with Result

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wallymathieucommented, Aug 30, 2020

Seems unintentional.

0reactions
gustycommented, Sep 30, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found