ekmett / transformers-compat

transformers compatibility shim
Other
10 stars 12 forks source link

Should transformers-compat backport orphan MonadFail instances? #40

Closed RyanGlScott closed 5 years ago

RyanGlScott commented 5 years ago

While upgrading some libraries to support base-4.13, where fail is now exclusively a method of MonadFail, I attempted to change some Monad constraints to MonadFail to make the API consistent across all versions of GHC. Alas, this caused the code to no longer compile on pre-8.0 versions of GHC, since I later instantiated those functions at monad transformer types like ReaderT, IdentityT, etc., and the fail compatibility package does not define MonadFail instances for those types. Unfortunately, this leaves me in a bit of a rut.

I talked with @hvr about this at one point, and he was hesitant to add orphan MonadFail instances to fail so as to keep the package as minimal as possible. This is a reasonable request, but it leaves the Haskell ecosystem without a canonical source for these useful orphan instances.

Since transformers-compat already provides an orphan instances module (in Control.Monad.Trans.Instances), I propose that we simply add the orphan MonadFail instances there. This has one drawback in that we will have to incur a dependency on the fail package on pre-8.0 GHCs, but I think the payoff would be worth it. Plus, there is already precedent for doing this, since transformers-compat already depends on mtl, another lightweight package.

RyanGlScott commented 5 years ago

41

cartazio commented 5 years ago

@RyanGlScott this would probably be nice to have. Is there any reason not to?

RyanGlScott commented 5 years ago

The only downside is that we'd have to add another library dependency to transformers-compat, which is itself pretty low on the dependency chain. As I mention in https://github.com/ekmett/transformers-compat/issues/40#issue-424537624, I think it would be worth it in the end, since fail is itself extremely lightweight and would only need to be depended upon if one uses a version of GHC older than 8.0.

ekmett commented 5 years ago

I have no objection to picking up a dependency on fail.