Skip to content

Commit

Permalink
Fix build warnings for using * instead of Data.Kind.Type (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
EarlPitts authored Oct 10, 2023
1 parent 459ecef commit e54f2bc
Show file tree
Hide file tree
Showing 36 changed files with 133 additions and 76 deletions.
3 changes: 2 additions & 1 deletion servant-auth/servant-auth-docs/src/Servant/Auth/Docs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module Servant.Auth.Docs
) where

import Control.Lens ((%~), (&), (|>))
import Data.Kind (Type)
import Data.List (intercalate)
import Data.Monoid
import Data.Proxy (Proxy (Proxy))
Expand Down Expand Up @@ -63,7 +64,7 @@ pretty rs =
)


class AllDocs (x :: [*]) where
class AllDocs (x :: [Type]) where
allDocs :: proxy x
-- intro, req
-> [(String, String)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Servant.Auth.Server.Internal.AddSetCookie where

import Blaze.ByteString.Builder (toByteString)
import qualified Data.ByteString as BS
import Data.Kind (Type)
import qualified Network.HTTP.Types as HTTP
import Network.Wai (mapResponseHeaders)
import Servant
Expand All @@ -33,12 +34,12 @@ type family AddSetCookieApiVerb a where
AddSetCookieApiVerb a = Headers '[Header "Set-Cookie" SetCookie] a

#if MIN_VERSION_servant_server(0,18,1)
type family MapAddSetCookieApiVerb (as :: [*]) where
type family MapAddSetCookieApiVerb (as :: [Type]) where
MapAddSetCookieApiVerb '[] = '[]
MapAddSetCookieApiVerb (a ': as) = (AddSetCookieApiVerb a ': MapAddSetCookieApiVerb as)
#endif

type family AddSetCookieApi a :: *
type family AddSetCookieApi a :: Type
type instance AddSetCookieApi (a :> b) = a :> AddSetCookieApi b
type instance AddSetCookieApi (a :<|> b) = AddSetCookieApi a :<|> AddSetCookieApi b
#if MIN_VERSION_servant_server(0,19,0)
Expand All @@ -57,7 +58,7 @@ type instance AddSetCookieApi (Stream method stat framing ctyps a)
#endif
type instance AddSetCookieApi (Headers hs a) = AddSetCookieApiVerb (Headers hs a)

data SetCookieList (n :: Nat) :: * where
data SetCookieList (n :: Nat) :: Type where
SetCookieNil :: SetCookieList 'Z
SetCookieCons :: Maybe SetCookie -> SetCookieList n -> SetCookieList ('S n)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Servant.Auth.Server.Internal.Class where

import Servant.Auth
import Data.Kind (Type)
import Data.Monoid
import Servant hiding (BasicAuth)

Expand All @@ -16,7 +17,7 @@ import Servant.Auth.Server.Internal.JWT (jwtAuthCheck)
-- elements of @ctx@ to be the in the Context and whose authentication check
-- returns an @AuthCheck v@.
class IsAuth a v where
type family AuthArgs a :: [*]
type family AuthArgs a :: [Type]
runAuth :: proxy a -> proxy v -> Unapp (AuthArgs a) (AuthCheck v)

instance FromJWT usr => IsAuth Cookie usr where
Expand All @@ -33,7 +34,7 @@ instance FromBasicAuthData usr => IsAuth BasicAuth usr where

-- * Helper

class AreAuths (as :: [*]) (ctxs :: [*]) v where
class AreAuths (as :: [Type]) (ctxs :: [Type]) v where
runAuths :: proxy as -> Context ctxs -> AuthCheck v

instance AreAuths '[] ctxs v where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Servant.Auth.Swagger
) where

import Control.Lens ((&), (<>~))
import Data.Kind (Type)
import Data.Proxy (Proxy (Proxy))
import Data.Swagger (ApiKeyLocation (..), ApiKeyParams (..),
SecurityRequirement (..), SecurityScheme (..),
Expand Down Expand Up @@ -66,7 +67,7 @@ instance HasSecurity JWT where
type_ = SecuritySchemeApiKey (ApiKeyParams "Authorization" ApiKeyHeader)
desc = "JSON Web Token-based API key"

class AllHasSecurity (x :: [*]) where
class AllHasSecurity (x :: [Type]) where
securities :: Proxy x -> [(T.Text,SecurityScheme)]

instance {-# OVERLAPPABLE #-} (HasSecurity x, AllHasSecurity xs) => AllHasSecurity (x ': xs) where
Expand Down
9 changes: 5 additions & 4 deletions servant-auth/servant-auth/src/Servant/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{-# LANGUAGE TypeOperators #-}
module Servant.Auth where

import Data.Kind (Type)
import Data.Proxy (Proxy(..))
import Servant.API ((:>))
import Servant.Links (HasLink (..))
Expand All @@ -13,15 +14,15 @@ import Servant.Links (HasLink (..))

-- | @Auth [auth1, auth2] val :> api@ represents an API protected *either* by
-- @auth1@ or @auth2@
data Auth (auths :: [*]) val
data Auth (auths :: [Type]) val

-- | A @HasLink@ instance for @Auth@
instance HasLink sub => HasLink (Auth (tag :: [*]) value :> sub) where
instance HasLink sub => HasLink (Auth (tag :: [Type]) value :> sub) where
#if MIN_VERSION_servant(0,14,0)
type MkLink (Auth (tag :: [*]) value :> sub) a = MkLink sub a
type MkLink (Auth (tag :: [Type]) value :> sub) a = MkLink sub a
toLink toA _ = toLink toA (Proxy :: Proxy sub)
#else
type MkLink (Auth (tag :: [*]) value :> sub) = MkLink sub
type MkLink (Auth (tag :: [Type]) value :> sub) = MkLink sub
toLink _ = toLink (Proxy :: Proxy sub)
#endif

Expand Down
10 changes: 6 additions & 4 deletions servant-client-core/src/Servant/Client/Core/HasClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import Data.Either
import Data.Constraint (Dict(..))
import Data.Foldable
(toList)
import Data.Kind
(Type)
import Data.List
(foldl')
import Data.Sequence
Expand Down Expand Up @@ -128,7 +130,7 @@ clientIn p pm = clientWithRoute pm p defaultRequest
-- combinators that you want to support client-generation, you can ignore this
-- class.
class RunClient m => HasClient m api where
type Client (m :: * -> *) (api :: *) :: *
type Client (m :: Type -> Type) (api :: Type) :: Type
clientWithRoute :: Proxy m -> Proxy api -> Request -> Client m api
hoistClientMonad
:: Proxy m
Expand Down Expand Up @@ -333,7 +335,7 @@ instance {-# OVERLAPPING #-}
data ClientParseError = ClientParseError MediaType String | ClientStatusMismatch | ClientNoMatchingStatus
deriving (Eq, Show)

class UnrenderResponse (cts :: [*]) (a :: *) where
class UnrenderResponse (cts :: [Type]) (a :: Type) where
unrenderResponse :: Seq.Seq H.Header -> BL.ByteString -> Proxy cts
-> [Either (MediaType, String) a]

Expand Down Expand Up @@ -840,7 +842,7 @@ instance HasClient m api => HasClient m (BasicAuth realm usr :> api) where
hoistClientMonad pm (Proxy :: Proxy api) f (cl bauth)

-- | A type that specifies that an API record contains a client implementation.
data AsClientT (m :: * -> *)
data AsClientT (m :: Type -> Type)
instance GenericMode (AsClientT m) where
type AsClientT m :- api = Client m api

Expand All @@ -850,7 +852,7 @@ type GClientConstraints api m =
, Client m (ToServantApi api) ~ ToServant api (AsClientT m)
)

class GClient (api :: * -> *) m where
class GClient (api :: Type -> Type) m where
gClientProof :: Dict (GClientConstraints api m)

instance GClientConstraints api m => GClient api m where
Expand Down
6 changes: 4 additions & 2 deletions servant-foreign/src/Servant/Foreign/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Control.Lens
(Getter, makeLenses, makePrisms, (%~), (&), (.~), (<>~))
import Data.Data
(Data)
import Data.Kind
(Type)
import Data.Proxy
import Data.String
import Data.Text
Expand Down Expand Up @@ -274,8 +276,8 @@ instance HasForeignType NoTypes NoContent a where
-- | Implementation of the Servant framework types.
--
-- Relevant instances: Everything containing 'HasForeignType'.
class HasForeign lang ftype (api :: *) where
type Foreign ftype api :: *
class HasForeign lang ftype (api :: Type) where
type Foreign ftype api :: Type
foreignFor :: Proxy lang -> Proxy ftype -> Proxy api -> Req ftype -> Foreign ftype api

instance (HasForeign lang ftype a, HasForeign lang ftype b)
Expand Down
4 changes: 3 additions & 1 deletion servant-server/src/Servant/Server/Experimental/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module Servant.Server.Experimental.Auth where

import Control.Monad.Trans
(liftIO)
import Data.Kind
(Type)
import Data.Proxy
(Proxy (Proxy))
import Data.Typeable
Expand All @@ -38,7 +40,7 @@ import Servant.Server.Internal
-- quite often this is some `User` datatype.
--
-- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
type family AuthServerData a :: *
type family AuthServerData a :: Type

-- | Handlers for AuthProtected resources
--
Expand Down
6 changes: 4 additions & 2 deletions servant-server/src/Servant/Server/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module Servant.Server.Generic (
genericServerT
) where

import Data.Kind
(Type)
import Data.Proxy
(Proxy (..))

Expand All @@ -37,7 +39,7 @@ genericServe = serve (Proxy :: Proxy (ToServantApi routes)) . genericServer
-- by providing a transformation to bring each handler back in the 'Handler'
-- monad.
genericServeT
:: forall (routes :: * -> *) (m :: * -> *).
:: forall (routes :: Type -> Type) (m :: Type -> Type).
( GenericServant routes (AsServerT m)
, GenericServant routes AsApi
, HasServer (ToServantApi routes) '[]
Expand All @@ -55,7 +57,7 @@ genericServeT f server = serve p $ hoistServer p f (genericServerT server)
-- used by auth-related combinators in servant, e.g to hold auth checks) and the given
-- transformation to map all the handlers back to the 'Handler' monad.
genericServeTWithContext
:: forall (routes :: * -> *) (m :: * -> *) (ctx :: [*]).
:: forall (routes :: Type -> Type) (m :: Type -> Type) (ctx :: [Type]).
( GenericServant routes (AsServerT m)
, GenericServant routes AsApi
, HasServer (ToServantApi routes) ctx
Expand Down
12 changes: 6 additions & 6 deletions servant-server/src/Servant/Server/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import qualified Data.ByteString.Lazy as BL
import Data.Constraint (Constraint, Dict(..))
import Data.Either
(partitionEithers)
import Data.Kind
(Type)
import Data.Maybe
(fromMaybe, isNothing, mapMaybe, maybeToList)
import Data.String
Expand Down Expand Up @@ -97,8 +99,6 @@ import Servant.API.TypeErrors
import Web.HttpApiData
(FromHttpApiData, parseHeader, parseQueryParam, parseUrlPiece,
parseUrlPieces)
import Data.Kind
(Type)

import Servant.Server.Internal.BasicAuth
import Servant.Server.Internal.Context
Expand All @@ -121,7 +121,7 @@ class HasServer api context where
--
-- Note that the result kind is @*@, so it is /not/ a monad transformer, unlike
-- what the @T@ in the name might suggest.
type ServerT api (m :: * -> *) :: *
type ServerT api (m :: Type -> Type) :: Type

route ::
Proxy api
Expand Down Expand Up @@ -900,7 +900,7 @@ instance TypeError (PartialApplication
#endif
HasServer arr) => HasServer ((arr :: a -> b) :> sub) context
where
type ServerT (arr :> sub) _ = TypeError (PartialApplication (HasServer :: * -> [*] -> Constraint) arr)
type ServerT (arr :> sub) _ = TypeError (PartialApplication (HasServer :: Type -> [Type] -> Constraint) arr)
route = error "unreachable"
hoistServerWithContext _ _ _ _ = error "unreachable"

Expand Down Expand Up @@ -973,7 +973,7 @@ instance (AtLeastOneFragment api, FragmentUnique (Fragment a1 :> api), HasServer
-- >>> import Servant

-- | A type that specifies that an API record contains a server implementation.
data AsServerT (m :: * -> *)
data AsServerT (m :: Type -> Type)
instance GenericMode (AsServerT m) where
type AsServerT m :- api = ServerT api m

Expand All @@ -999,7 +999,7 @@ type GServerConstraints api m =
-- Users shouldn't have to worry about this class, as the only possible instance
-- is provided in this module for all record APIs.

class GServer (api :: * -> *) (m :: * -> *) where
class GServer (api :: Type -> Type) (m :: Type -> Type) where
gServerProof :: Dict (GServerConstraints api m)

instance
Expand Down
8 changes: 5 additions & 3 deletions servant-server/src/Servant/Server/Internal/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

module Servant.Server.Internal.Context where

import Data.Kind
(Type)
import Data.Proxy
import GHC.TypeLits

Expand Down Expand Up @@ -51,7 +53,7 @@ instance (Eq a, Eq (Context as)) => Eq (Context (a ': as)) where
-- Hint: import it as
--
-- > import Servant.Server (type (.++))
type family (.++) (l1 :: [*]) (l2 :: [*]) where
type family (.++) (l1 :: [Type]) (l2 :: [Type]) where
'[] .++ a = a
(a ': as) .++ b = a ': (as .++ b)

Expand All @@ -73,7 +75,7 @@ EmptyContext .++ a = a
-- ...
-- ...No instance for ...HasContextEntry '[] [Char]...
-- ...
class HasContextEntry (context :: [*]) (val :: *) where
class HasContextEntry (context :: [Type]) (val :: Type) where
getContextEntry :: Context context -> val

instance {-# OVERLAPPABLE #-}
Expand All @@ -90,7 +92,7 @@ instance {-# OVERLAPPING #-}
-- to have multiple values of the same type in your 'Context' and need to access
-- them, we provide 'NamedContext'. You can think of it as sub-namespaces for
-- 'Context's.
data NamedContext (name :: Symbol) (subContext :: [*])
data NamedContext (name :: Symbol) (subContext :: [Type])
= NamedContext (Context subContext)

-- | 'descendIntoNamedContext' allows you to access `NamedContext's. Usually you
Expand Down
6 changes: 4 additions & 2 deletions servant-server/src/Servant/Server/Internal/ErrorFormatter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module Servant.Server.Internal.ErrorFormatter
, mkContextWithErrorFormatter
) where

import Data.Kind
(Type)
import Data.String.Conversions
(cs)
import Data.Typeable
Expand Down Expand Up @@ -67,9 +69,9 @@ type ErrorFormatter = TypeRep -> Request -> String -> ServerError
-- | This formatter does not get neither 'TypeRep' nor error message.
type NotFoundErrorFormatter = Request -> ServerError

type MkContextWithErrorFormatter (ctx :: [*]) = ctx .++ DefaultErrorFormatters
type MkContextWithErrorFormatter (ctx :: [Type]) = ctx .++ DefaultErrorFormatters

mkContextWithErrorFormatter :: forall (ctx :: [*]). Context ctx -> Context (MkContextWithErrorFormatter ctx)
mkContextWithErrorFormatter :: forall (ctx :: [Type]). Context ctx -> Context (MkContextWithErrorFormatter ctx)
mkContextWithErrorFormatter ctx = ctx .++ (defaultErrorFormatters :. EmptyContext)

-- Internal
Expand Down
5 changes: 3 additions & 2 deletions servant-server/src/Servant/Server/UVerb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Servant.Server.UVerb
where

import qualified Data.ByteString as B
import Data.Kind (Type)
import Data.Proxy (Proxy (Proxy))
import Data.SOP (I (I))
import Data.SOP.Constraint (All, And)
Expand All @@ -39,13 +40,13 @@ import Servant.Server.Internal (Context, Delayed, Handler, HasServer (..), Route
-- | 'return' for 'UVerb' handlers. Takes a value of any of the members of the open union,
-- and will construct a union value in an 'Applicative' (eg. 'Server').
respond ::
forall (x :: *) (xs :: [*]) (f :: * -> *).
forall (x :: Type) (xs :: [Type]) (f :: Type -> Type).
(Applicative f, HasStatus x, IsMember x xs) =>
x ->
f (Union xs)
respond = pure . inject . I

class IsServerResource (cts :: [*]) a where
class IsServerResource (cts :: [Type]) a where
resourceResponse :: Request -> Proxy cts -> a -> Maybe (LBS, LBS)
resourceHeaders :: Proxy cts -> a -> [(HeaderName, B.ByteString)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
module Servant.Swagger.Internal.TypeLevel.API where

import GHC.Exts (Constraint)
import Data.Kind (Type)
import Servant.API

-- | Build a list of endpoints from an API.
Expand Down Expand Up @@ -75,7 +76,7 @@ type AddBodyType c cs a as = If (Elem c cs) (a ': as) as
-- @'NoContent'@ is removed from the list and not tested. (This allows for leaving the body
-- completely empty on responses to requests that only accept 'application/json', while
-- setting the content-type in the response accordingly.)
type family BodyTypes' c api :: [*] where
type family BodyTypes' c api :: [Type] where
BodyTypes' c (Verb verb b cs (Headers hdrs a)) = AddBodyType c cs a '[]
BodyTypes' c (Verb verb b cs NoContent) = '[]
BodyTypes' c (Verb verb b cs a) = AddBodyType c cs a '[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#endif
module Servant.Swagger.Internal.TypeLevel.Every where

import Data.Kind
(Type)
import Data.Proxy
import GHC.Exts (Constraint)

Expand Down Expand Up @@ -48,7 +50,7 @@ type family EveryTF cs x :: Constraint where
-- | Apply multiple constraint constructors to a type as a class.
--
-- This is different from @'EveryTF'@ in that it allows partial application.
class EveryTF cs x => Every (cs :: [* -> Constraint]) (x :: *) where
class EveryTF cs x => Every (cs :: [Type -> Constraint]) (x :: Type) where

instance Every '[] x where
instance (c x, Every cs x) => Every (c ': cs) x where
Expand Down
Loading

0 comments on commit e54f2bc

Please sign in to comment.