Skip to content

Commit

Permalink
Use the Applicative instance for the Parser (awakesecurity#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell authored and Gabriella439 committed Apr 15, 2019
1 parent 45bff3f commit 67d52c2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Proto3/Suite/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module Proto3.Suite.Class
, GenericMessage(..)
) where

import Control.Applicative
import Control.Monad
import qualified Data.ByteString as B
import qualified Data.ByteString.Base64 as B64
Expand Down Expand Up @@ -672,7 +673,7 @@ class GenericMessage (f :: * -> *) where
instance GenericMessage U1 where
type GenericFieldCount U1 = 0
genericEncodeMessage _ = mempty
genericDecodeMessage _ = return U1
genericDecodeMessage _ = pure U1
genericDotProto _ = mempty

instance (KnownNat (GenericFieldCount f), GenericMessage f, GenericMessage g)
Expand All @@ -686,7 +687,7 @@ instance (KnownNat (GenericFieldCount f), GenericMessage f, GenericMessage g)
offset = fromIntegral $ natVal (Proxy @(GenericFieldCount f))

genericDecodeMessage num =
liftM2 (:*:) (genericDecodeMessage num)
liftA2 (:*:) (genericDecodeMessage num)
(genericDecodeMessage num2)
where
num2 = FieldNumber $ getFieldNumber num + offset
Expand Down

0 comments on commit 67d52c2

Please sign in to comment.