Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parsonsmatt/exceptiot
A type `ExceptIOT` which uses `IO` for the `MonadError` instance, allowing a `MonadUnliftIO` instance
https://github.com/parsonsmatt/exceptiot
Last synced: 10 days ago
JSON representation
A type `ExceptIOT` which uses `IO` for the `MonadError` instance, allowing a `MonadUnliftIO` instance
- Host: GitHub
- URL: https://github.com/parsonsmatt/exceptiot
- Owner: parsonsmatt
- License: bsd-3-clause
- Created: 2022-11-22T18:15:32.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2022-11-22T23:38:14.000Z (almost 2 years ago)
- Last Synced: 2024-03-15T02:52:00.370Z (8 months ago)
- Language: Haskell
- Size: 18.6 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# `exceptiot`
Sometimes, it is nice to write code in `MonadError` to indicate that the code
can throw an exception.```haskell
foo :: MonadError FooError m => Int -> m Char
```We can call `foo` in `Either FooError` for a pure test, or a `ExceptT FooError
IO` if we are writing in some monad directly. However, sometimes you can't use
`ExceptT`. One possible reason is performance: `ExceptT` can add overhead.
Another reason is `MonadUnliftIO` - `ExceptT` cannot have an instance for this.You don't want to *stop* using `MonadError`, but you also can't use `ExceptT`
anymore. What can you do?```haskell
import Control.Monad.Except.IOmain :: IO ()
main = do
eres <- runExceptIOT (foo 3)
case eres of
Left FooError ->
putStrLn "got FooError"
Right c ->
putChar c
```You can replace `ExceptT` with `ExceptIOT`, and all exception use will switch to
`IO` based exceptions instead of `Either`-based values. This allows you to use
`MonadUnliftIO` without fear.