Created
July 8, 2015 19:37
-
-
Save codedmart/a4e058f26b9e72cf6cfe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data ApiInfo = ApiInfo { | |
| name :: T.Text, | |
| version :: T.Text | |
| } deriving (Eq, Generic) | |
| instance FromJSON ApiInfo | |
| instance ToJSON ApiInfo | |
| data Config = Config { | |
| info :: ApiInfo | |
| , dbHost :: HostName | |
| , port :: Int | |
| } | |
| data AppConfig = AppConfig { | |
| pool :: (Pool RethinkDBHandle) | |
| , config :: Config | |
| } | |
| data AppOptions = AppOptions { | |
| env :: String | |
| } deriving (Data,Typeable) | |
| type AppIO = ReaderT AppConfig (EitherT ServantErr IO) | |
| type API = | |
| Get ApiInfo | |
| :<|> "users" :> UsersAPI | |
| serverT :: ServerT API AppIO | |
| serverT = | |
| getApiInfo | |
| :<|> usersServer | |
| where | |
| getApiInfo :: AppIO ApiInfo | |
| getApiInfo = apiInfo | |
| appIOToEither' :: AppConfig -> AppIO a -> EitherT ServantErr IO a | |
| appIOToEither' t r = runReaderT (hoist (EitherT . runEitherT) r) t | |
| appIOToEither :: AppConfig -> AppIO :~> EitherT ServantErr IO | |
| appIOToEither t = Nat $ appIOToEither' t | |
| api :: Proxy API | |
| api = Proxy | |
| server :: AppConfig -> Server API | |
| server t = enter (appIOToEither t) serverT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
EitherT . runEitherT is equivalent to id isn't it? It doesn't do anything? I'm still confused about what hoist does. I looked at my code and appIOToEither' seems equivalent to my runAppT, and your code doesn't seem any shorter for using it. Can you take it out? Maybe it isn't doing anything.