git.iko.soy/typeable/servant
on master help sign in
Merge pull request #74 from haskell-servant/wip-whitespace-comment

servant: clean up some white spaces, add link explaining why Or works.

commite59c03faa2be0b3ca48c2e7c2b3b49ee40c39958 authorAlp Mestanogullari <alpmestan@gmail.com> dateSat 16 May 2015, 08:28 (11 years ago) parent955261dd1b9043
1 file changed+24−22
servant/src/Servant/Utils/Links.hs+24−22
servant/src/Servant/Utils/Links.hs+24−22
@@ -138,15 +138,17 @@ data Link = Link
138138
139139-- | If either a or b produce an empty constraint, produce an empty constraint.
140140type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
141+ -- This works because of:
142+ -- https://ghc.haskell.org/trac/ghc/wiki/NewAxioms/CoincidentOverlap
141143 Or () b = ()
142144 Or a () = ()
143145
144146-- | If both a or b produce an empty constraint, produce an empty constraint.
145147type family And (a :: Constraint) (b :: Constraint) :: Constraint where
146− And () () = ()
148+ And () () = ()
147149
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
150+-- | You may use this type family to tell the type checker that your custom
151+-- type may be skipped as part of a link. This is useful for things like
150152-- 'QueryParam' that are optional in a URI and do not affect them if they are
151153-- omitted.
152154--
@@ -162,30 +164,30 @@ type family IsElem' a s :: Constraint
162164
163165-- | Closed type family, check if endpoint is within api
164166type 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
167+ IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb)
168+ IsElem (e :> sa) (e :> sb) = IsElem sa sb
169+ IsElem sa (Header x :> sb) = IsElem sa sb
170+ IsElem sa (ReqBody y x :> sb) = IsElem sa sb
171+ IsElem (e :> sa) (Capture x y :> sb) = IsElem sa sb
172+ IsElem sa (QueryParam x y :> sb) = IsElem sa sb
173+ IsElem sa (QueryParams x y :> sb) = IsElem sa sb
174+ IsElem sa (QueryFlag x :> sb) = IsElem sa sb
175+ IsElem sa (MatrixParam x y :> sb) = IsElem sa sb
176+ IsElem sa (MatrixParams x y :> sb) = IsElem sa sb
177+ IsElem sa (MatrixFlag x :> sb) = IsElem sa sb
178+ IsElem (Get ct typ) (Get ct' typ) = IsSubList ct ct'
179+ IsElem (Post ct typ) (Post ct' typ) = IsSubList ct ct'
180+ IsElem (Put ct typ) (Put ct' typ) = IsSubList ct ct'
181+ IsElem (Delete ct typ) (Delete ct' typ) = IsSubList ct ct'
182+ IsElem e e = ()
183+ IsElem e a = IsElem' e a
182184
183185
184186type family IsSubList a b :: Constraint where
185− IsSubList '[] b = ()
187+ IsSubList '[] b = ()
186188 IsSubList '[x] (x ': xs) = ()
187189 IsSubList '[x] (y ': ys) = IsSubList '[x] ys
188− IsSubList (x ': xs) y = IsSubList '[x] y `And` IsSubList xs y
190+ IsSubList (x ': xs) y = IsSubList '[x] y `And` IsSubList xs y
189191
190192-- Phantom types for Param
191193data Matrix