{"action":"created","issue":{"url":"https://api.github.com/repos/input-output-hk/cardano-sl/issues/2507","repository_url":"https://api.github.com/repos/input-output-hk/cardano-sl","labels_url":"https://api.github.com/repos/input-output-hk/cardano-sl/issues/2507/labels{/name}","comments_url":"https://api.github.com/repos/input-output-hk/cardano-sl/issues/2507/comments","events_url":"https://api.github.com/repos/input-output-hk/cardano-sl/issues/2507/events","html_url":"https://github.com/input-output-hk/cardano-sl/pull/2507","id":296531350,"number":2507,"title":"[CSL-2117] Allow careful usage of ExceptT over IO","user":{"login":"int-index","id":4061728,"avatar_url":"https://avatars1.githubusercontent.com/u/4061728?v=4","gravatar_id":"","url":"https://api.github.com/users/int-index","html_url":"https://github.com/int-index","followers_url":"https://api.github.com/users/int-index/followers","following_url":"https://api.github.com/users/int-index/following{/other_user}","gists_url":"https://api.github.com/users/int-index/gists{/gist_id}","starred_url":"https://api.github.com/users/int-index/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/int-index/subscriptions","organizations_url":"https://api.github.com/users/int-index/orgs","repos_url":"https://api.github.com/users/int-index/repos","events_url":"https://api.github.com/users/int-index/events{/privacy}","received_events_url":"https://api.github.com/users/int-index/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":57,"created_at":"2018-02-12T21:31:31Z","updated_at":"2018-02-17T23:20:53Z","closed_at":null,"author_association":"COLLABORATOR","pull_request":{"url":"https://api.github.com/repos/input-output-hk/cardano-sl/pulls/2507","html_url":"https://github.com/input-output-hk/cardano-sl/pull/2507","diff_url":"https://github.com/input-output-hk/cardano-sl/pull/2507.diff","patch_url":"https://github.com/input-output-hk/cardano-sl/pull/2507.patch"},"body":"There are two reasons to avoid `ExceptT` over `IO`:\r\n\r\n* it creates a separate exception handling mechanism overlapping with `IO` exceptions\r\n* it doesn't have a `MonadMask` instance, so `bracket` cannot be used with it\r\n\r\nThe first reason can be mitigated by making the sets of `ExceptT` and `IO` exceptions disjoint:\r\n\r\n* `throwError` must be used only with types that have a `TypeError \"Not an exception\" => Exception e` instance (requirement of our guidelines)\r\n* `throwM` and `throwIO` require a working `Exception e` instance\r\n\r\nThis means that the two mechanisms are not in conflict, but actually complement each other. One is useful for checked exceptions and general control flow, while the other — for unchecked exceptions.\r\n\r\nAs to `MonadMask`, this will be fixed in the next `exceptions` release.\r\n"},"comment":{"url":"https://api.github.com/repos/input-output-hk/cardano-sl/issues/comments/366478878","html_url":"https://github.com/input-output-hk/cardano-sl/pull/2507#issuecomment-366478878","issue_url":"https://api.github.com/repos/input-output-hk/cardano-sl/issues/2507","id":366478878,"user":{"login":"int-index","id":4061728,"avatar_url":"https://avatars1.githubusercontent.com/u/4061728?v=4","gravatar_id":"","url":"https://api.github.com/users/int-index","html_url":"https://github.com/int-index","followers_url":"https://api.github.com/users/int-index/followers","following_url":"https://api.github.com/users/int-index/following{/other_user}","gists_url":"https://api.github.com/users/int-index/gists{/gist_id}","starred_url":"https://api.github.com/users/int-index/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/int-index/subscriptions","organizations_url":"https://api.github.com/users/int-index/orgs","repos_url":"https://api.github.com/users/int-index/repos","events_url":"https://api.github.com/users/int-index/events{/privacy}","received_events_url":"https://api.github.com/users/int-index/received_events","type":"User","site_admin":false},"created_at":"2018-02-17T23:20:53Z","updated_at":"2018-02-17T23:20:53Z","author_association":"COLLABORATOR","body":"> Can we really speak on an \"exit\" here? The program could evaluate `Right 42` before it evaluates `Left e`.\r\n\r\nIs the evaluation order relevant here? The definition of early exit that I gave above, `m >>= f = m`, works for both strict and lazy languages.\r\n\r\n> I didn't claim that throwing it as an IO exception doesn't communicate the same information. But now that you mention it I will say that it doesn't communicate it quite as well: the type of the thing that throws it makes no mention of MyError.\r\n\r\nOh, I agree! That's why I want to exclude *redundancy*: if throwing `MyError` with `ExceptT` is just a better way of doing the same with `IO`, then let's statically guarantee that there aren't terms in our program that throw `MyError` in both ways.\r\n\r\n> I'll try to oblige. Here's an easy one: if you don't have IO, don't throw an IO exception, and never add any constraints just so that you can do so. That's to say, if you're not already doing IO for your business, then don't throw an IO exception.\r\n\r\nThat's very good advice, thanks! That's also something that our guidelines already recommend: in pure code, use `ExceptT` and `Either`. What we're discussing here is when we already have `IO`, `MonadIO m`, or potentially impure code that can be instantiated to `m ~ IO`. And in this case, all I want is to guarantee that `ExceptT` and `IO` aren't used for the same type of exception simultaneously.\r\n\r\n> Sure there is: `throwIO e` is a program. It crashes.\r\n\r\nI don't think I follow your terminology. `throwIO e` is a term, not a program. A program consists of types, terms, etc, and in the end compiles to a binary that the user can run. When I use `throwIO e`, it's not something that crashes either, consider `main = const (return ()) (throwIO e)`. Not even a mention of `catch`. A program crashes when there's a `throwIO e` term in it that gets executed (because it's a part of the `main` term) and doesn't get caught."}}
{"actor":{"display_login":"int-index"}}