{"action":"opened","issue":{"url":"https://api.github.com/repos/silkapp/rest/issues/144","labels_url":"https://api.github.com/repos/silkapp/rest/issues/144/labels{/name}","comments_url":"https://api.github.com/repos/silkapp/rest/issues/144/comments","events_url":"https://api.github.com/repos/silkapp/rest/issues/144/events","html_url":"https://github.com/silkapp/rest/issues/144","id":122781949,"number":144,"title":"rest-example - example of handling nested ReaderT","user":{"login":"ronslow","id":835136,"avatar_url":"https://avatars.githubusercontent.com/u/835136?v=3","gravatar_id":"","url":"https://api.github.com/users/ronslow","html_url":"https://github.com/ronslow","followers_url":"https://api.github.com/users/ronslow/followers","following_url":"https://api.github.com/users/ronslow/following{/other_user}","gists_url":"https://api.github.com/users/ronslow/gists{/gist_id}","starred_url":"https://api.github.com/users/ronslow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronslow/subscriptions","organizations_url":"https://api.github.com/users/ronslow/orgs","repos_url":"https://api.github.com/users/ronslow/repos","events_url":"https://api.github.com/users/ronslow/events{/privacy}","received_events_url":"https://api.github.com/users/ronslow/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-17T17:21:44Z","updated_at":"2015-12-17T17:21:44Z","closed_at":null,"body":"I am following rest-examples, simplifying, and building a service to return a single Booking, identified by BookingId, from an (AcidState Diary)\r\n\r\nnewtype DiaryApi a = DiaryApi { unDiaryApi :: ReaderT (AcidState Diary) IO a }\r\n  deriving ( Applicative\r\n           , Functor\r\n           , Monad\r\n           , MonadIO\r\n           , MonadReader (AcidState Diary)\r\n             \r\n           )\r\n           \r\ntype WithBookingId = ReaderT BookingId DiaryApi\r\n\r\nresource ::  Resource DiaryApi WithBookingId BookingId Void Void\r\nresource = mkResourceReader { R.name = \"booking\"\r\n \r\n                            , R.get = Just getBooking\r\n                            }\r\n\r\ngetBooking ::  Handler WithBookingId\r\ngetBooking = mkIdHandler jsonO handler where\r\n  handler :: () -> BookingId -> ExceptT (Reason Void) WithBookingId  Booking\r\n  handler _ bid = do\r\n   diary <- lift $ DiaryApi $ lift $ ask -- this is the problem line\r\n   return $ liftIO $ query diary (GetBooking bid) -- this line is looking up the booking in the AcidState Diary, works within IO, and is known to be correct\r\n\r\nThe problem line of course lifts the diary into a ExceptT (Reason Void) BookingApi Booking monad, whereas I need it to be inside an ExceptT (Reason Void) WithBookingId Booking monad\r\n\r\nAm I going about this in the right way? Is it correct to nest ReaderT in this way for subresources?\r\n\r\nRobert\r\n\r\n\r\n"}}