git.iko.soy/typeable/servant
on master help sign in
servant: clean up some white spaces, add link explaining why Or works.
13fcb4fChristian Marie
servant/src/Servant/Utils/Links.hs+25−22
@@ -137,16 +137,19 @@ data Link = Link
137 } deriving Show
137 } deriving Show
138
138
139-- | If either a or b produce an empty constraint, produce an empty constraint.
139-- | If either a or b produce an empty constraint, produce an empty constraint.
140+--
141+-- This works because of:
142+-- https://ghc.haskell.org/trac/ghc/wiki/NewAxioms/CoincidentOverlap
140type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
143type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
141 Or () b = ()
144 Or () b = ()
142 Or a () = ()
145 Or a () = ()
143
146
144-- | If both a or b produce an empty constraint, produce an empty constraint.
147-- | If both a or b produce an empty constraint, produce an empty constraint.
145type family And (a :: Constraint) (b :: Constraint) :: Constraint where
148type family And (a :: Constraint) (b :: Constraint) :: Constraint where
146− And () () = ()
149+ And () () = ()
147
150
148−-- | You may use this type family to tell the type checker that your custom type
151+-- | You may use this type family to tell the type checker that your custom
149−-- may be skipped as part of a link. This is useful for things like
152+-- type may be skipped as part of a link. This is useful for things like
150-- 'QueryParam' that are optional in a URI and do not affect them if they are
153-- 'QueryParam' that are optional in a URI and do not affect them if they are
151-- omitted.
154-- omitted.
152--
155--
@@ -162,30 +165,30 @@ type family IsElem' a s :: Constraint
162
165
163-- | Closed type family, check if endpoint is within api
166-- | Closed type family, check if endpoint is within api
164type family IsElem endpoint api :: Constraint where
167type family IsElem endpoint api :: Constraint where
165− IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb)
168+ IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb)
166− IsElem (e :> sa) (e :> sb) = IsElem sa sb
169+ IsElem (e :> sa) (e :> sb) = IsElem sa sb
167− IsElem sa (Header x :> sb) = IsElem sa sb
170+ IsElem sa (Header x :> sb) = IsElem sa sb
168− IsElem sa (ReqBody y x :> sb) = IsElem sa sb
171+ IsElem sa (ReqBody y x :> sb) = IsElem sa sb
169− IsElem (e :> sa) (Capture x y :> sb) = IsElem sa sb
172+ IsElem (e :> sa) (Capture x y :> sb) = IsElem sa sb
170− IsElem sa (QueryParam x y :> sb) = IsElem sa sb
173+ IsElem sa (QueryParam x y :> sb) = IsElem sa sb
171− IsElem sa (QueryParams x y :> sb) = IsElem sa sb
174+ IsElem sa (QueryParams x y :> sb) = IsElem sa sb
172− IsElem sa (QueryFlag x :> sb) = IsElem sa sb
175+ IsElem sa (QueryFlag x :> sb) = IsElem sa sb
173− IsElem sa (MatrixParam x y :> sb) = IsElem sa sb
176+ IsElem sa (MatrixParam x y :> sb) = IsElem sa sb
174− IsElem sa (MatrixParams x y :> sb) = IsElem sa sb
177+ IsElem sa (MatrixParams x y :> sb) = IsElem sa sb
175− IsElem sa (MatrixFlag x :> sb) = IsElem sa sb
178+ IsElem sa (MatrixFlag x :> sb) = IsElem sa sb
176− IsElem (Get ct typ) (Get ct' typ) = IsSubList ct ct'
179+ IsElem (Get ct typ) (Get ct' typ) = IsSubList ct ct'
177− IsElem (Post ct typ) (Post ct' typ) = IsSubList ct ct'
180+ IsElem (Post ct typ) (Post ct' typ) = IsSubList ct ct'
178− IsElem (Put ct typ) (Put ct' typ) = IsSubList ct ct'
181+ IsElem (Put ct typ) (Put ct' typ) = IsSubList ct ct'
179− IsElem (Delete ct typ) (Delete ct' typ) = IsSubList ct ct'
182+ IsElem (Delete ct typ) (Delete ct' typ) = IsSubList ct ct'
180− IsElem e e = ()
183+ IsElem e e = ()
181− IsElem e a = IsElem' e a
184+ IsElem e a = IsElem' e a
182
185
183
186
184type family IsSubList a b :: Constraint where
187type family IsSubList a b :: Constraint where
185− IsSubList '[] b = ()
188+ IsSubList '[] b = ()
186 IsSubList '[x] (x ': xs) = ()
189 IsSubList '[x] (x ': xs) = ()
187 IsSubList '[x] (y ': ys) = IsSubList '[x] ys
190 IsSubList '[x] (y ': ys) = IsSubList '[x] ys
188− IsSubList (x ': xs) y = IsSubList '[x] y `And` IsSubList xs y
191+ IsSubList (x ': xs) y = IsSubList '[x] y `And` IsSubList xs y
189
192
190-- Phantom types for Param
193-- Phantom types for Param
191data Matrix
194data Matrix