git.iko.soy/typeable/servant
on master help sign in
Add details about AddHeaders instances (#1490)

* Add details about the instances of AddHeader Also: * Cleanup of extensions and imports

commita975cfc36193b8bc52c75ae5af224a64363dc4ed authorThéophile Choutri <theophile@choutri.eu> dateTue 30 Nov 2021, 23:52 (5 years ago) parent9a39799
2 files changed+7−11
.gitignore+1 servant/src/Servant/API/ResponseHeaders.hs+6−11
.gitignore+1
@@ -31,6 +31,7 @@ doc/venv
3131doc/tutorial/static/api.js
3232doc/tutorial/static/jq.js
3333shell.nix
34+.hspec-failures
3435
3536# nix
3637result*
servant/src/Servant/API/ResponseHeaders.hs+6−11
@@ -3,10 +3,8 @@
33{-# LANGUAGE DeriveFunctor #-}
44{-# LANGUAGE FlexibleContexts #-}
55{-# LANGUAGE FlexibleInstances #-}
6−{-# LANGUAGE FunctionalDependencies #-}
76{-# LANGUAGE GADTs #-}
8−{-# LANGUAGE KindSignatures #-}
9−{-# LANGUAGE MultiParamTypeClasses #-}
7+{-# LANGUAGE FunctionalDependencies #-}
108{-# LANGUAGE PolyKinds #-}
119{-# LANGUAGE ScopedTypeVariables #-}
1210{-# LANGUAGE TypeFamilies #-}
@@ -51,9 +49,6 @@ import Web.HttpApiData
5149
5250import Prelude ()
5351import Prelude.Compat
54−import Servant.API.ContentTypes
55− (JSON, PlainText, FormUrlEncoded, OctetStream,
56− MimeRender(..))
5752import Servant.API.Header
5853 (Header)
5954
@@ -117,7 +112,7 @@ instance {-# OVERLAPPABLE #-} ( FromHttpApiData v, BuildHeadersTo xs, KnownSymbo
117112 `HCons` buildHeadersTo headers
118113 Right h -> Header h `HCons` buildHeadersTo headers
119114
120−-- * Getting
115+-- * Getting headers
121116
122117class GetHeaders ls where
123118 getHeaders :: ls -> [HTTP.Header]
@@ -158,20 +153,20 @@ instance (KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v)
158153 where
159154 getHeaders' hs = getHeadersFromHList $ getHeadersHList hs
160155
161−-- * Adding
156+-- * Adding headers
162157
163158-- We need all these fundeps to save type inference
164159class AddHeader h v orig new
165160 | h v orig -> new, new -> h, new -> v, new -> orig where
166161 addOptionalHeader :: ResponseHeader h v -> orig -> new -- ^ N.B.: The same header can't be added multiple times
167162
168−
163+-- In this instance, we add a Header on top of something that is already decorated with some headers
169164instance {-# OVERLAPPING #-} ( KnownSymbol h, ToHttpApiData v )
170165 => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': fst ': rest) a) where
171166 addOptionalHeader hdr (Headers resp heads) = Headers resp (HCons hdr heads)
172167
173−instance {-# OVERLAPPABLE #-} ( KnownSymbol h, ToHttpApiData v
174− , new ~ (Headers '[Header h v] a) )
168+-- In this instance, 'a' parameter is decorated with a Header.
169+instance {-# OVERLAPPABLE #-} ( KnownSymbol h, ToHttpApiData v , new ~ Headers '[Header h v] a)
175170 => AddHeader h v a new where
176171 addOptionalHeader hdr resp = Headers resp (HCons hdr HNil)
177172