git.iko.soy/typeable/servant
on master help sign in
servant: clean up some white spaces, add link explaining why Or works.
commit13fcb4f3f104e0941182da5b83e43b0bf9efcb09 authorChristian Marie <christian@ponies.io> dateThu 14 May 2015, 00:07 (11 years ago) parentc87b846
1 file changed+25−22
servant/src/Servant/Utils/Links.hs+25−22
servant/src/Servant/Utils/Links.hs+25−22
@@ -137,16 +137,19 @@ data Link = Link
137137 } deriving Show
138138
139139-- | 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
140143type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
141144 Or () b = ()
142145 Or a () = ()
143146
144147-- | If both a or b produce an empty constraint, produce an empty constraint.
145148type family And (a :: Constraint) (b :: Constraint) :: Constraint where
146− And () () = ()
149+ And () () = ()
147150
148−-- | You may use this type family to tell the type checker that your custom type
149−-- may be skipped as part of a link. This is useful for things like
151+-- | You may use this type family to tell the type checker that your custom
152+-- type may be skipped as part of a link. This is useful for things like
150153-- 'QueryParam' that are optional in a URI and do not affect them if they are
151154-- omitted.
152155--
@@ -162,30 +165,30 @@ type family IsElem' a s :: Constraint
162165
163166-- | Closed type family, check if endpoint is within api
164167type family IsElem endpoint api :: Constraint where
165− IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb)
166− IsElem (e :> sa) (e :> sb) = IsElem sa sb
167− IsElem sa (Header x :> sb) = IsElem sa sb
168− IsElem sa (ReqBody y x :> sb) = IsElem sa sb
169− IsElem (e :> sa) (Capture x y :> sb) = IsElem sa sb
170− IsElem sa (QueryParam x y :> sb) = IsElem sa sb
171− IsElem sa (QueryParams x y :> sb) = IsElem sa sb
172− IsElem sa (QueryFlag x :> sb) = IsElem sa sb
173− IsElem sa (MatrixParam x y :> sb) = IsElem sa sb
174− IsElem sa (MatrixParams x y :> sb) = IsElem sa sb
175− IsElem sa (MatrixFlag x :> sb) = IsElem sa sb
176− IsElem (Get ct typ) (Get ct' typ) = IsSubList ct ct'
177− IsElem (Post ct typ) (Post ct' typ) = IsSubList ct ct'
178− IsElem (Put ct typ) (Put ct' typ) = IsSubList ct ct'
179− IsElem (Delete ct typ) (Delete ct' typ) = IsSubList ct ct'
180− IsElem e e = ()
181− IsElem e a = IsElem' e a
168+ IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb)
169+ IsElem (e :> sa) (e :> sb) = IsElem sa sb
170+ IsElem sa (Header x :> sb) = IsElem sa sb
171+ IsElem sa (ReqBody y x :> sb) = IsElem sa sb
172+ IsElem (e :> sa) (Capture x y :> sb) = IsElem sa sb
173+ IsElem sa (QueryParam x y :> sb) = IsElem sa sb
174+ IsElem sa (QueryParams x y :> sb) = IsElem sa sb
175+ IsElem sa (QueryFlag x :> sb) = IsElem sa sb
176+ IsElem sa (MatrixParam x y :> sb) = IsElem sa sb
177+ IsElem sa (MatrixParams x y :> sb) = IsElem sa sb
178+ IsElem sa (MatrixFlag x :> sb) = IsElem sa sb
179+ IsElem (Get ct typ) (Get ct' typ) = IsSubList ct ct'
180+ IsElem (Post ct typ) (Post ct' typ) = IsSubList ct ct'
181+ IsElem (Put ct typ) (Put ct' typ) = IsSubList ct ct'
182+ IsElem (Delete ct typ) (Delete ct' typ) = IsSubList ct ct'
183+ IsElem e e = ()
184+ IsElem e a = IsElem' e a
182185
183186
184187type family IsSubList a b :: Constraint where
185− IsSubList '[] b = ()
188+ IsSubList '[] b = ()
186189 IsSubList '[x] (x ': xs) = ()
187190 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
189192
190193-- Phantom types for Param
191194data Matrix