Skip to content

Instantly share code, notes, and snippets.

@codedmart
Created July 8, 2015 19:37
Show Gist options
  • Select an option

  • Save codedmart/a4e058f26b9e72cf6cfe to your computer and use it in GitHub Desktop.

Select an option

Save codedmart/a4e058f26b9e72cf6cfe to your computer and use it in GitHub Desktop.
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
@seanhess
Copy link
Copy Markdown

seanhess commented Jul 8, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment