@@ -2,6 +2,7 @@
22{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
33{-# LANGUAGE PatternGuards, ScopedTypeVariables #-}
44{-# LANGUAGE RecordWildCards #-}
5+{-# LANGUAGE PolyKinds #-}
56
67{- |
78Module: Database.PostgreSQL.Simple.FromField
@@ -115,7 +116,7 @@ module Database.PostgreSQL.Simple.FromField
115116
116117#include "MachDeps.h"
117118
118−import Control.Applicative ( (<|>), (<$>), pure, (*>), (<*) )
119+import Control.Applicative ( Const(Const), (<|>), (<$>), pure, (*>), (<*) )
119120import Control.Concurrent.MVar (MVar, newMVar)
120121import Control.Exception (Exception)
121122import qualified Data.Aeson as JSON
@@ -124,6 +125,7 @@ import qualified Data.Aeson.Parser as JSON (value')
124125import Data.Attoparsec.ByteString.Char8 hiding (Result)
125126import Data.ByteString (ByteString)
126127import qualified Data.ByteString.Char8 as B
128+import Data.Functor.Identity (Identity(Identity))
127129import Data.Int (Int16, Int32, Int64)
128130import Data.IORef (IORef, newIORef)
129131import Data.Ratio (Ratio)
@@ -269,6 +271,12 @@ instance FromField () where
269271 | typeOid f /= TI.voidOid = returnError Incompatible f ""
270272 | otherwise = pure ()
271273
274+instance (FromField a) => FromField (Const a b) where
275+ fromField f bs = Const <$> fromField f bs
276+
277+instance (FromField a) => FromField (Identity a) where
278+ fromField f bs = Identity <$> fromField f bs
279+
272280-- | For dealing with null values. Compatible with any postgresql type
273281-- compatible with type @a@. Note that the type is not checked if
274282-- the value is null, although it is inadvisable to rely on this