Merge pull request #890 from mgsloan/kinder-type-checking

Kinder type checking
This commit is contained in:
Alp Mestanogullari 2018-01-18 08:25:26 +01:00 committed by GitHub
commit 345dc8a1bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 10 deletions

View File

@ -12,7 +12,7 @@ import GHC.TypeLits (Symbol)
--
-- >>> -- GET /books/:isbn
-- >>> type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
data Capture (sym :: Symbol) a
data Capture (sym :: Symbol) (a :: *)
deriving (Typeable)
@ -23,7 +23,7 @@ data Capture (sym :: Symbol) a
--
-- >>> -- GET /src/*
-- >>> type MyAPI = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile
data CaptureAll (sym :: Symbol) a
data CaptureAll (sym :: Symbol) (a :: *)
deriving (Typeable)
-- $setup

View File

@ -14,7 +14,7 @@ import GHC.TypeLits (Symbol)
--
-- >>> -- /books?author=<author name>
-- >>> type MyApi = "books" :> QueryParam "author" Text :> Get '[JSON] [Book]
data QueryParam (sym :: Symbol) a
data QueryParam (sym :: Symbol) (a :: *)
deriving Typeable
-- | Lookup the values associated to the @sym@ query string parameter
@ -28,7 +28,7 @@ data QueryParam (sym :: Symbol) a
--
-- >>> -- /books?authors[]=<author1>&authors[]=<author2>&...
-- >>> type MyApi = "books" :> QueryParams "authors" Text :> Get '[JSON] [Book]
data QueryParams (sym :: Symbol) a
data QueryParams (sym :: Symbol) (a :: *)
deriving Typeable
-- | Lookup a potentially value-less query string parameter

View File

@ -11,7 +11,7 @@ import Data.Typeable (Typeable)
--
-- >>> -- POST /books
-- >>> type MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book
data ReqBody (contentTypes :: [*]) a
data ReqBody (contentTypes :: [*]) (a :: *)
deriving (Typeable)
-- $setup

View File

@ -23,7 +23,7 @@ import Control.Arrow (first)
import Network.HTTP.Types.Method (StdMethod (..))
-- | A Stream endpoint for a given method emits a stream of encoded values at a given Content-Type, delimited by a framing strategy. Steam endpoints always return response code 200 on success. Type synonyms are provided for standard methods.
data Stream (method :: k1) (framing :: *) (contentType :: *) a
data Stream (method :: k1) (framing :: *) (contentType :: *) (a :: *)
deriving (Typeable, Generic)
type StreamGet = Stream 'GET

View File

@ -14,7 +14,7 @@ import Data.Typeable (Typeable)
-- >>> -- GET /hello/world
-- >>> -- returning a JSON encoded World value
-- >>> type MyApi = "hello" :> "world" :> Get '[JSON] World
data (path :: k) :> a
data (path :: k) :> (a :: *)
deriving (Typeable)
infixr 4 :>

View File

@ -23,7 +23,7 @@ import Network.HTTP.Types.Method (Method, StdMethod (..),
-- provided, but you are free to define your own:
--
-- >>> type Post204 contentTypes a = Verb 'POST 204 contentTypes a
data Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [*]) a
data Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [*]) (a :: *)
deriving (Typeable, Generic)
-- * 200 responses

View File

@ -24,7 +24,7 @@ type TestApi =
-- All of the verbs
:<|> "get" :> Get '[JSON] NoContent
:<|> "put" :> Put '[JSON] NoContent
:<|> "post" :> ReqBody '[JSON] 'True :> Post '[JSON] NoContent
:<|> "post" :> ReqBody '[JSON] Bool :> Post '[JSON] NoContent
:<|> "delete" :> Header "ponies" String :> Delete '[JSON] NoContent
:<|> "raw" :> Raw
:<|> NoEndpoint
@ -124,6 +124,6 @@ type WrongPath = "getTypo" :> Get '[JSON] NoContent
type WrongReturnType = "get" :> Get '[JSON] Bool
type WrongContentType = "get" :> Get '[OctetStream] NoContent
type WrongMethod = "get" :> Post '[JSON] NoContent
type NotALink = "hello" :> ReqBody '[JSON] 'True :> Get '[JSON] Bool
type NotALink = "hello" :> ReqBody '[JSON] Bool :> Get '[JSON] Bool
type AllGood = "get" :> Get '[JSON] NoContent
type NoEndpoint = "empty" :> EmptyAPI