packages feed

describe 0.3.1.0 → 0.3.1.1

raw patch · 5 files changed

+24/−12 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Serialize.Describe.Combinators.FList: instance Data.Serialize.Describe.Combinators.FList.Nullable GHC.Word.Word16
+ Data.Serialize.Describe.Combinators.FList: flist :: (Describe a, Nullable a) => Int -> (s -> [a]) -> Descriptor s [a]
+ Data.Serialize.Describe.Combinators.FList: instance GHC.Num.Num n => Data.Serialize.Describe.Combinators.FList.Nullable (Data.Serialize.Describe.Combinators.BE.BE n)
+ Data.Serialize.Describe.Combinators.FList: instance GHC.Num.Num n => Data.Serialize.Describe.Combinators.FList.Nullable (Data.Serialize.Describe.Combinators.LE.LE n)
+ Data.Serialize.Describe.Combinators.FList: instance GHC.Num.Num n => Data.Serialize.Describe.Combinators.FList.Nullable n

Files

CHANGELOG.md view
@@ -1,6 +1,10 @@ # Revision history for describe -##0.3.0.1 -- 2020-01-09+##0.3.1.1 -- 2020-01-09++* Added flist combinator++##0.3.1.0 -- 2020-01-09  * Added NText combinator 
describe.cabal view
@@ -3,7 +3,7 @@ --   For further documentation, see http://haskell.org/cabal/users-guide/  name:                describe-version:             0.3.1.0+version:             0.3.1.1 synopsis:            Combinators for describing binary data structures description:         Combinators for describing binary data structures, which eliminate the boilerplate of having to write isomorphic Get and Put instances. Please see the Github page for examples. homepage:            https://github.com/riugabachi/describe@@ -29,6 +29,7 @@                       TypeOperators,                       OverlappingInstances,                       LambdaCase,+                      StandaloneDeriving,                       GeneralizedNewtypeDeriving,                       FlexibleContexts,                       DefaultSignatures,
src/Data/Serialize/Describe/Combinators/FList.hs view
@@ -3,11 +3,20 @@ import GHC.TypeNats import Data.Proxy import Data.Serialize.Describe-import Data.Word import Data.Serialize.Describe.Combinators.Const+import Data.Serialize.Describe.Combinators.BE+import Data.Serialize.Describe.Combinators.LE import Control.Monad --- | A type level wrapper around a fixed-length list combinator, with similar semantics to @FText@. The list element must be @Nullable@, meaning that it must have default value that can be used for padding the list if need be.+-- | A fixed-length list combinator, with similar semantics to @FText@. The list element must be @Nullable@, meaning that it must have default value that can be used for padding the list if need be.+flist :: (Describe a, Nullable a) => Int -> (s -> [a]) -> Descriptor s [a]+flist fixedLen f = +  forM [0..fixedLen - 1] $ \i -> +    describe $ \l ->+      let actualLen = length . take fixedLen $ f l+       in (!! i) . (<> replicate (fixedLen - actualLen) nullVal) $ f l++-- | A type level wrapper around @flist@. newtype FList (n :: Nat) a    = FList { unwrapFList :: [a] }   deriving (Show) via [a]@@ -15,17 +24,15 @@ class Nullable a where   nullVal :: a -instance Nullable Word16 where+instance Num n => Nullable n where   nullVal = 0 +deriving instance Num n => Nullable (LE n)+deriving instance Num n => Nullable (BE n)+ instance Nullable (Const n a) where   nullVal = Const  instance (KnownNat n, Nullable a, Describe a) => Describe (FList n a) where   describe f = do-    let fixedLen = fromIntegral (natVal $ Proxy @n)-    fmap FList . forM [0..fixedLen - 1] $ \i -> -      describe $ \l ->-        let actualLen = length . take fixedLen . unwrapFList $ f l-         in (!! i) . (<> replicate (fixedLen - actualLen) (nullVal @a)) . unwrapFList $ f l-+    FList <$> flist (fromIntegral (natVal $ Proxy @n)) (unwrapFList . f)
src/Data/Serialize/Describe/Combinators/NText.hs view
@@ -1,6 +1,5 @@ module Data.Serialize.Describe.Combinators.NText where -import Data.Word import Data.Char import Data.String import Data.Text (Text)
src/Data/Serialize/Describe/Descriptor.hs view
@@ -8,6 +8,7 @@ ) where  import Control.Exception+import Control.Monad.Fail import Data.ByteString (ByteString) import Data.Serialize.Get import Data.Serialize.Put