yesodweb/Shelly.hs — pull request #57 by jwiegley (2014-04-22 05:39:38+00:00)
Title: Modify shelly to support lifted operations

Hi Greg!

Here is the very first cut. I'm submitting this as a pull request simply to begin a conversation on the best direction(s) for the code to go in. I intentionally have not finished it yet, because at this point I just wanted to prove that the concept works, and to get your feedback.

Here is what I have working now:

- Using `lifted-base` and `lifted-async`, you can freely use `async`, `try`, `catch`, etc., within `Sh` blocks. This does *not* require importing `Shelly.Lifted`, but works with existing code. This eliminates the need for `asyncSh` and the other `_sh` variants of the exception handling functions.

- If you `import Shelly.Lifted`, all the higher-order functions (like `sub`, `withTmpDir`, etc.) can work within any of the standard transformers (`MaybeT`, `StateT`, etc).

- There is a `liftSh` function, for lifting functions written in `Sh` rather than abstracted over `MonadSh`.

What's left to do:

- Provide re-exports in `Shelly.Lifted` for every function in `Shelly`, abstracting them over `MonadSh`. The goal here is to avoid the need to use `liftSh` with any of Shelly's own functions. The real purpose of `liftSh` is to allow users to call their own functions written in `Sh`.

- Finish writing the `MonadShControl` instances. The need for these instances is truly a hideous thing, but users will never see it, and it gives us great flexibility. Basically, we are using `MonadBaseControl IO` to allow `lifted-base` and `lifted-async` to work, and `MonadShControl` to allow things like the newly abstracted `sub` to work. I had to fork my own Shelly-specific brand of `monad-control` to do this, because you can't have two bases (`lifted-async` needs to see IO as the base, and `sub` needs to see `Sh` as the base).

- Mark the `_sh` exception handling variants as deprecated.

- Write more tests.

There is only about 3 hours more work left to do, but I wanted you to have a chance to review what I've done so far, to see if the approach is even acceptable to you.