Skip to content

Commit

Permalink
Merge pull request #43 from sopvop/master
Browse files Browse the repository at this point in the history
Overlapping instances for ReaderT
  • Loading branch information
mightybyte committed Nov 27, 2016
2 parents ee2e17b + d3eed97 commit e13906d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Snap/Snaplet/PostgresqlSimple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@ instance HasPostgres (Handler b Postgres) where
--
-- > d <- nestSnaplet "db" db pgsInit
-- > count <- liftIO $ runReaderT (execute "INSERT ..." params) d
instance (MonadIO m, MonadBaseControl IO m) => HasPostgres (ReaderT (Snaplet Postgres) m) where
instance {-# OVERLAPPING #-} (MonadIO m, MonadBaseControl IO m)
=> HasPostgres (ReaderT (Snaplet Postgres) m) where
getPostgresState = asks (^# snapletValue)
setLocalPostgresState s = local (set snapletValue s)

------------------------------------------------------------------------------
-- | A convenience instance to make it easier to use functions written for
-- this snaplet in non-snaplet contexts.
instance (MonadIO m, MonadBaseControl IO m) => HasPostgres (ReaderT Postgres m) where
instance {-# OVERLAPPING #-} (MonadIO m, MonadBaseControl IO m)
=> HasPostgres (ReaderT Postgres m) where
getPostgresState = ask
setLocalPostgresState s = local (const s)

Expand Down
2 changes: 1 addition & 1 deletion src/Snap/Snaplet/PostgresqlSimple/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ instance HasPostgres m => HasPostgres (MaybeT m) where
setLocalPostgresState pg m


instance HasPostgres m => HasPostgres (ReaderT r m) where
instance {-#OVERLAPPABLE #-} HasPostgres m => HasPostgres (ReaderT r m) where
getPostgresState = lift getPostgresState
setLocalPostgresState pg (ReaderT m) = ReaderT $ \e ->
setLocalPostgresState pg (m e)
Expand Down

0 comments on commit e13906d

Please sign in to comment.