Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions hpgsql/src/Hpgsql/Msgs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Hpgsql.Msgs (AuthenticationResponse (..), AuthenticationMethod (..), Back

import Control.Applicative (Alternative (..))
import Control.Monad (replicateM)
import Control.Monad.Trans.Reader (ReaderT (..))
import qualified Crypto.Hash as Crypto
import qualified Data.Attoparsec.ByteString as Parsec
import qualified Data.Attoparsec.ByteString.Lazy as LazyParsec
Expand Down Expand Up @@ -38,16 +39,7 @@ newtype PgMsgParser a
Maybe a
)
deriving stock (Functor)

instance Applicative PgMsgParser where
pure a = PgMsgParser $ \_ _ -> Just a

-- TODO: Is this Applicative correct? Double-check laws
PgMsgParser f <*> PgMsgParser p = PgMsgParser $ \c r -> f c r <*> p c r

instance Alternative PgMsgParser where
empty = PgMsgParser $ \_ _ -> Nothing
PgMsgParser p1 <|> PgMsgParser p2 = PgMsgParser $ \c restOfMsg -> p1 c restOfMsg <|> p2 c restOfMsg
deriving (Applicative, Alternative) via (ReaderT Char (ReaderT LBS.ByteString Maybe))

class FromPgMessage a where
msgParser :: PgMsgParser a
Expand Down