on dev help sign in
simplify some binary instance code
commit3a2c8cffd3f0440f15287d1360eb2c7963fd6ae9 authorEitan Chatav <eitan.chatav@gmail.com> dateSat 14 Jul 2018, 11:17 (8 years ago) parent76b19bf
1 file changed+9−15
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+9−15
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+9−15
@@ -436,22 +436,16 @@ instance
436436 -- <value: <length> bytes>
437437 -- [end if]
438438 -- [end for]
439− composite
440− :: forall pgs. SListI pgs
441− => Strict.ByteString
442− -> Either Strict.Text (NP (K (Maybe Strict.ByteString)) pgs)
443439 composite = Decoding.valueParser $ do
444440 unitOfSize 4
445− let
446− each _ = do
447− unitOfSize 4
448− len <- sized 4 Decoding.int
449− if len == -1
450− then return (K Nothing)
451− else K . Just <$> bytesOfSize len
452− htraverse' each (hpure Proxy :: NP Proxy pgs)
441+ hsequence' $ hpure $ Comp $ do
442+ unitOfSize 4
443+ len <- sized 4 Decoding.int
444+ if len == -1
445+ then return (K Nothing)
446+ else K . Just <$> bytesOfSize len
453447 in
454− Decoding.fn (fromRow @fields @y <=< composite)
448+ Decoding.fn (fromRow @fields <=< composite)
455449
456450-- | A `FromField` constraint lifts the `FromValue` parser
457451-- to a decoding of a @(Symbol, NullityType)@ to a `Type`,
@@ -466,13 +460,13 @@ instance FromValue pg y
466460 fromField = Comp . \case
467461 K Nothing -> Left "fromField: saw NULL when expecting NOT NULL"
468462 K (Just bytestring) -> P <$>
469− Decoding.valueParser (fromValue @pg @y) bytestring
463+ Decoding.valueParser (fromValue @pg) bytestring
470464instance FromValue pg y
471465 => FromField (column ::: 'Null pg) (column ::: Maybe y) where
472466 fromField = Comp . \case
473467 K Nothing -> Right $ P Nothing
474468 K (Just bytestring) -> P . Just <$>
475− Decoding.valueParser (fromValue @pg @y) bytestring
469+ Decoding.valueParser (fromValue @pg) bytestring
476470
477471-- | A `FromRow` constraint generically sequences the parsings of the columns
478472-- of a `RelationType` into the fields of a record `Type` provided they have