@@ -1,4 +1,3 @@
2{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
3{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
4{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveDataTypeable #-}
@@ -14,8 +13,6 @@
14{-# LANGUAGE UndecidableInstances #-}
13{-# LANGUAGE UndecidableInstances #-}
15{-# OPTIONS_HADDOCK not-home #-}
14{-# OPTIONS_HADDOCK not-home #-}
17−#include "overlapping-compat.h"
19-- | A collection of basic Content-Types (also known as Internet Media
16-- | A collection of basic Content-Types (also known as Internet Media
20-- Types, or MIME types). Additionally, this module provides classes that
17-- Types, or MIME types). Additionally, this module provides classes that
21-- encapsulate how to serialize or deserialize values to or from
18-- encapsulate how to serialize or deserialize values to or from
@@ -98,16 +95,13 @@ import qualified Data.Text.Lazy.Encoding as TextL
98import Data.Typeable
95import Data.Typeable
99import GHC.Generics
96import GHC.Generics
100 (Generic)
97 (Generic)
98+import qualified GHC.TypeLits as TL
101import qualified Network.HTTP.Media as M
99import qualified Network.HTTP.Media as M
102import Prelude ()
100import Prelude ()
103import Prelude.Compat
101import Prelude.Compat
104import Web.FormUrlEncoded
102import Web.FormUrlEncoded
105 (FromForm, ToForm, urlDecodeAsForm, urlEncodeAsForm)
103 (FromForm, ToForm, urlDecodeAsForm, urlEncodeAsForm)
107−#if MIN_VERSION_base(4,9,0)
108−import qualified GHC.TypeLits as TL
111-- * Provided content types
105-- * Provided content types
112data JSON deriving Typeable
106data JSON deriving Typeable
113data PlainText deriving Typeable
107data PlainText deriving Typeable
@@ -185,18 +179,16 @@ class (AllMime list) => AllCTRender (list :: [*]) a where
185 -- mimetype).
179 -- mimetype).
186 handleAcceptH :: Proxy list -> AcceptHeader -> a -> Maybe (ByteString, ByteString)
180 handleAcceptH :: Proxy list -> AcceptHeader -> a -> Maybe (ByteString, ByteString)
188−instance OVERLAPPABLE_
182+instance {-# OVERLAPPABLE #-}
189 (Accept ct, AllMime cts, AllMimeRender (ct ': cts) a) => AllCTRender (ct ': cts) a where
183 (Accept ct, AllMime cts, AllMimeRender (ct ': cts) a) => AllCTRender (ct ': cts) a where
190 handleAcceptH _ (AcceptHeader accept) val = M.mapAcceptMedia lkup accept
184 handleAcceptH _ (AcceptHeader accept) val = M.mapAcceptMedia lkup accept
191 where pctyps = Proxy :: Proxy (ct ': cts)
185 where pctyps = Proxy :: Proxy (ct ': cts)
192 amrs = allMimeRender pctyps val
186 amrs = allMimeRender pctyps val
193 lkup = fmap (\(a,b) -> (a, (fromStrict $ M.renderHeader a, b))) amrs
187 lkup = fmap (\(a,b) -> (a, (fromStrict $ M.renderHeader a, b))) amrs
195−#if MIN_VERSION_base(4,9,0)
196instance TL.TypeError ('TL.Text "No instance for (), use NoContent instead.")
189instance TL.TypeError ('TL.Text "No instance for (), use NoContent instead.")
197 => AllCTRender '[] () where
190 => AllCTRender '[] () where
198 handleAcceptH _ _ _ = error "unreachable"
191 handleAcceptH _ _ _ = error "unreachable"
201--------------------------------------------------------------------------
193--------------------------------------------------------------------------
202-- * Unrender
194-- * Unrender
@@ -277,13 +269,13 @@ class (AllMime list) => AllMimeRender (list :: [*]) a where
277 -> a -- value to serialize
269 -> a -- value to serialize
278 -> [(M.MediaType, ByteString)] -- content-types/response pairs
270 -> [(M.MediaType, ByteString)] -- content-types/response pairs
280−instance OVERLAPPABLE_ ( MimeRender ctyp a ) => AllMimeRender '[ctyp] a where
272+instance {-# OVERLAPPABLE #-} ( MimeRender ctyp a ) => AllMimeRender '[ctyp] a where
281 allMimeRender _ a = map (, bs) $ NE.toList $ contentTypes pctyp
273 allMimeRender _ a = map (, bs) $ NE.toList $ contentTypes pctyp
283 bs = mimeRender pctyp a
275 bs = mimeRender pctyp a
284 pctyp = Proxy :: Proxy ctyp
276 pctyp = Proxy :: Proxy ctyp
286−instance OVERLAPPABLE_
278+instance {-# OVERLAPPABLE #-}
287 ( MimeRender ctyp a
279 ( MimeRender ctyp a
288 , AllMimeRender (ctyp' ': ctyps) a
280 , AllMimeRender (ctyp' ': ctyps) a
289 ) => AllMimeRender (ctyp ': ctyp' ': ctyps) a where
281 ) => AllMimeRender (ctyp ': ctyp' ': ctyps) a where
@@ -299,12 +291,12 @@ instance OVERLAPPABLE_
299-- Ideally we would like to declare a 'MimeRender a NoContent' instance, and
291-- Ideally we would like to declare a 'MimeRender a NoContent' instance, and
300-- then this would be taken care of. However there is no more specific instance
292-- then this would be taken care of. However there is no more specific instance
301-- between that and 'MimeRender JSON a', so we do this instead
293-- between that and 'MimeRender JSON a', so we do this instead
302−instance OVERLAPPING_ ( Accept ctyp ) => AllMimeRender '[ctyp] NoContent where
294+instance {-# OVERLAPPING #-} ( Accept ctyp ) => AllMimeRender '[ctyp] NoContent where
303 allMimeRender _ _ = map (, "") $ NE.toList $ contentTypes pctyp
295 allMimeRender _ _ = map (, "") $ NE.toList $ contentTypes pctyp
305 pctyp = Proxy :: Proxy ctyp
297 pctyp = Proxy :: Proxy ctyp
307−instance OVERLAPPING_
299+instance {-# OVERLAPPING #-}
308 ( AllMime (ctyp ': ctyp' ': ctyps)
300 ( AllMime (ctyp ': ctyp' ': ctyps)
309 ) => AllMimeRender (ctyp ': ctyp' ': ctyps) NoContent where
301 ) => AllMimeRender (ctyp ': ctyp' ': ctyps) NoContent where
310 allMimeRender p _ = zip (allMime p) (repeat "")
302 allMimeRender p _ = zip (allMime p) (repeat "")
@@ -334,14 +326,14 @@ instance ( MimeUnrender ctyp a
334-- * MimeRender Instances
326-- * MimeRender Instances
336-- | `encode`
328-- | `encode`
337−instance OVERLAPPABLE_
329+instance {-# OVERLAPPABLE #-}
338 ToJSON a => MimeRender JSON a where
330 ToJSON a => MimeRender JSON a where
339 mimeRender _ = encode
331 mimeRender _ = encode
341-- | @urlEncodeAsForm@
333-- | @urlEncodeAsForm@
342-- Note that the @mimeUnrender p (mimeRender p x) == Right x@ law only
334-- Note that the @mimeUnrender p (mimeRender p x) == Right x@ law only
343-- holds if every element of x is non-null (i.e., not @("", "")@)
335-- holds if every element of x is non-null (i.e., not @("", "")@)
344−instance OVERLAPPABLE_
336+instance {-# OVERLAPPABLE #-}
345 ToForm a => MimeRender FormUrlEncoded a where
337 ToForm a => MimeRender FormUrlEncoded a where
346 mimeRender _ = urlEncodeAsForm
338 mimeRender _ = urlEncodeAsForm