jwiegley / gitlib

180 stars 56 forks source link

Replace ReaderT LgRepo monad stack with typeclass #69

Closed jamesdabbs closed 7 years ago

jamesdabbs commented 7 years ago

This defines a typeclass HasLgRepo m with getRepository :: m LgRepo to generalize the concrete ReaderT LgRepo m type with a HasLgRepo m => m constraint.

The motivating use case is: I'm writing a Yesod app and would like for my Handler monad stack to satisfy MonadGit LgRepo Handler. The existing implementation rather strongly forces me to use a ReaderT LgRepo Handler, but with this change it's trivial for me to define a HasLgRepo instance and get the desired MonadGit instance without having to manually specify all the MonadGit fields.

As far as I can tell, this should be fully backwards compatible, since instance Monad m => HasLgRepo (ReaderT LgRepo m) where getRepository = ask.

Somewhat new to Haskell PRs here, so if there's anything else I can do (documentation, tests) to help out, please feel free to indicate that, and I'd be happy to. Thanks for this project; it's been a big help!

jwiegley commented 7 years ago

Thanks!