2015-08-17 23:56:29 +02:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
2015-05-06 19:01:32 +02:00
|
|
|
{-# LANGUAGE TypeOperators #-}
|
2015-05-10 13:39:18 +02:00
|
|
|
module T7 where
|
2015-05-06 19:01:32 +02:00
|
|
|
|
2015-09-12 14:11:24 +02:00
|
|
|
import Control.Monad.Trans.Except
|
2015-08-17 23:56:29 +02:00
|
|
|
import Control.Monad.Trans.Reader
|
|
|
|
import Network.Wai
|
|
|
|
import Servant
|
2015-05-06 19:01:32 +02:00
|
|
|
|
|
|
|
type ReaderAPI = "a" :> Get '[JSON] Int
|
|
|
|
:<|> "b" :> Get '[JSON] String
|
|
|
|
|
|
|
|
readerAPI :: Proxy ReaderAPI
|
|
|
|
readerAPI = Proxy
|
|
|
|
|
|
|
|
readerServerT :: ServerT ReaderAPI (Reader String)
|
|
|
|
readerServerT = a :<|> b
|
|
|
|
|
|
|
|
where a :: Reader String Int
|
|
|
|
a = return 1797
|
|
|
|
|
|
|
|
b :: Reader String String
|
|
|
|
b = ask
|
|
|
|
|
|
|
|
readerServer :: Server ReaderAPI
|
|
|
|
readerServer = enter readerToEither readerServerT
|
|
|
|
|
2015-09-12 14:11:24 +02:00
|
|
|
where readerToEither :: Reader String :~> ExceptT ServantErr IO
|
2015-05-06 19:01:32 +02:00
|
|
|
readerToEither = Nat $ \r -> return (runReader r "hi")
|
|
|
|
|
|
|
|
app :: Application
|
2016-01-07 12:51:30 +01:00
|
|
|
app = serve readerAPI EmptyConfig readerServer
|