{"action":"created","issue":{"url":"https://api.github.com/repos/fsprojects/FSharpPlus/issues/135","repository_url":"https://api.github.com/repos/fsprojects/FSharpPlus","labels_url":"https://api.github.com/repos/fsprojects/FSharpPlus/issues/135/labels{/name}","comments_url":"https://api.github.com/repos/fsprojects/FSharpPlus/issues/135/comments","events_url":"https://api.github.com/repos/fsprojects/FSharpPlus/issues/135/events","html_url":"https://github.com/fsprojects/FSharpPlus/issues/135","id":375857674,"node_id":"MDU6SXNzdWUzNzU4NTc2NzQ=","number":135,"title":"\"Break early\" from monad CE","user":{"login":"cmeeren","id":7766733,"node_id":"MDQ6VXNlcjc3NjY3MzM=","avatar_url":"https://avatars0.githubusercontent.com/u/7766733?v=4","gravatar_id":"","url":"https://api.github.com/users/cmeeren","html_url":"https://github.com/cmeeren","followers_url":"https://api.github.com/users/cmeeren/followers","following_url":"https://api.github.com/users/cmeeren/following{/other_user}","gists_url":"https://api.github.com/users/cmeeren/gists{/gist_id}","starred_url":"https://api.github.com/users/cmeeren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmeeren/subscriptions","organizations_url":"https://api.github.com/users/cmeeren/orgs","repos_url":"https://api.github.com/users/cmeeren/repos","events_url":"https://api.github.com/users/cmeeren/events{/privacy}","received_events_url":"https://api.github.com/users/cmeeren/received_events","type":"User","site_admin":false},"labels":[{"id":558264926,"node_id":"MDU6TGFiZWw1NTgyNjQ5MjY=","url":"https://api.github.com/repos/fsprojects/FSharpPlus/labels/discussion","name":"discussion","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":21,"created_at":"2018-10-31T08:54:35Z","updated_at":"2018-11-01T21:03:33Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I have a `result` CE in [Cvdm.ErrorHandling](https://github.com/cmeeren/Cvdm.ErrorHandling/) for monadic error handling. For the example below, `sideEffect1` and `sideEffect2` are never invoked, since `do!` binds an error (I think also `Delay` is involved, but I don't have a clear grasp of CE builders).\r\n\r\n```f#\r\nlet _ = result {\r\n  if true then\r\n    do! Error err\r\n    sideEffect1 ()\r\n  sideEffect2 ()\r\n}\r\n```\r\n\r\nHowever, if I replace `result` with `monad` (or `monad.fx` or others, I've tried them all), the side effects are invoked.\r\n\r\nIs it possible to get my desired behavior using a generic CE from FSharpPlus?"},"comment":{"url":"https://api.github.com/repos/fsprojects/FSharpPlus/issues/comments/435186446","html_url":"https://github.com/fsprojects/FSharpPlus/issues/135#issuecomment-435186446","issue_url":"https://api.github.com/repos/fsprojects/FSharpPlus/issues/135","id":435186446,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTE4NjQ0Ng==","user":{"login":"gusty","id":1261319,"node_id":"MDQ6VXNlcjEyNjEzMTk=","avatar_url":"https://avatars3.githubusercontent.com/u/1261319?v=4","gravatar_id":"","url":"https://api.github.com/users/gusty","html_url":"https://github.com/gusty","followers_url":"https://api.github.com/users/gusty/followers","following_url":"https://api.github.com/users/gusty/following{/other_user}","gists_url":"https://api.github.com/users/gusty/gists{/gist_id}","starred_url":"https://api.github.com/users/gusty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gusty/subscriptions","organizations_url":"https://api.github.com/users/gusty/orgs","repos_url":"https://api.github.com/users/gusty/repos","events_url":"https://api.github.com/users/gusty/events{/privacy}","received_events_url":"https://api.github.com/users/gusty/received_events","type":"User","site_admin":false},"created_at":"2018-11-01T21:03:33Z","updated_at":"2018-11-01T21:03:33Z","author_association":"MEMBER","body":"In order to get a similar behavior to the asyncResult you need to use Monad Transformers.\r\n\r\nThe advantage of Monad Transformers is that you can combine the transformer with any monad, otherwise you would end up writing a lot of boilerplate, and any new monad will increase that boilerplate in an exponential way !\r\n\r\nMonad transformers are also monads, but they have a different type, that's why your snippet doesn't work as you expect: the compiler is not expecting an asyncResult monad by the sole fact that the result contains a result inside the Async. If that was the case, it would be trying to be too smart and it will apply the asyncResult in cases whare just the async was intended.\r\n\r\nYou ommited the definition of x, but I guess it's a plain string, so you're failing code is probably something like:\r\n\r\n```\r\nlet x = \"\"\r\nlet result : Result<string, string> =\r\n      (monad { return x }: Async<Result<string, string>>)\r\n      |> Async.RunSynchronously\r\n```\r\n\r\nYou can get it working, of course by setting `x` to `Ok \"\"`, but I think what you are after is this:\r\n\r\n```\r\nlet x = \"\"\r\nlet result : Result<string, string> =\r\n      (monad { return x }: ResultT<_>)\r\n      |> ResultT.run\r\n      |> Async.RunSynchronously"}}
{"actor":{"display_login":"gusty"}}