Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird try/with/finally behavior in monad CE #137

Closed
cmeeren opened this issue Oct 31, 2018 · 3 comments · Fixed by #347
Closed

Weird try/with/finally behavior in monad CE #137

cmeeren opened this issue Oct 31, 2018 · 3 comments · Fixed by #347

Comments

@cmeeren
Copy link
Contributor

cmeeren commented Oct 31, 2018

It doesn't seem that try catches exceptions. Repro (using xUnit and Unquote):

/// Helper type for simulating side effects.
type Trigger() =
  let mutable isTriggered = false
  member __.Trigger () = isTriggered <- true
  member __.Triggered = isTriggered

[<Fact>]
let ``behavior of try-with-finally when thrown`` () =
  let tTry = Trigger()
  let tCatch = Trigger()
  let tFinally = Trigger()

  let result = monad {
    try
      try
        failwith ""
        tTry.Trigger()
      with _ -> tCatch.Trigger()
    finally tFinally.Trigger()
  }
  test <@ result = Ok () @>
  test <@ not tTry.Triggered @>
  test <@ tCatch.Triggered @>
  test <@ tFinally.Triggered @>

None of the unquote tests are checked, because the exception is not caught, but they do describe what should happen if the exception is caught.

@gusty
Copy link
Member

gusty commented Nov 1, 2018

Interesting.

Obviously the reason is again because Result is not really lazy, using a strict workflow is the right thing.

Now this is another indication that mixing workflows (and autosensing them) is not that great.

We should definitely think about it, if we revert this decision we can release a new major version of the library, or we can deprecate existing workflows and create new one, which wouldn't require a new major release.

@wallymathieu
Copy link
Member

Can we close this issue in favor of #140 ?

@cmeeren
Copy link
Contributor Author

cmeeren commented Nov 3, 2018

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants