describe 0.1.0.0 → 0.1.1.0
raw patch · 4 files changed
+21/−17 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Data.Serialize.Descriptor: instance GHC.Base.Monad (Data.Serialize.Descriptor.Descriptor s)
- Data.Serialize.Descriptor: unwrapPut :: s -> Descriptor s a -> Put
+ Data.Serialize.Descriptor: unwrapPut :: s -> Descriptor s a -> PutM ()
Files
- CHANGELOG.md +4/−0
- Test.hs +0/−3
- describe.cabal +5/−7
- src/Data/Serialize/Descriptor.hs +12/−7
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for describe +## 0.1.1.0 -- 2019-09-05++* Added Monad instance for Descriptor+ ## 0.1.0.0 -- 2019-06-03 * Initial release.
Test.hs view
@@ -1,10 +1,7 @@ module Main where import Test.QuickCheck-import Test.QuickCheck.Monadic import Data.Word-import Data.Either-import qualified Data.ByteString as B import Data.Serialize.Descriptor import Data.Serialize.Descriptor.LE
describe.cabal view
@@ -3,19 +3,21 @@ -- For further documentation, see http://haskell.org/cabal/users-guide/ name: describe-version: 0.1.0.0+version: 0.1.1.0 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--- bug-reports: license: BSD-3-Clause license-file: LICENSE author: Riuga maintainer: n/a--- copyright: category: Data extra-source-files: CHANGELOG.md +source-repository head+ type: git+ location: https://github.com/RiugaBachi/describe.git+ common deps build-depends: base ^>= 4.12.0.0, cereal >= 0.5.8 && < 0.6,@@ -28,8 +30,6 @@ exposed-modules: Data.Serialize.Descriptor, Data.Serialize.Descriptor.LE, Data.Serialize.Descriptor.BE- -- other-modules:- -- other-extensions: hs-source-dirs: src test-suite describe-tests@@ -37,5 +37,3 @@ type: exitcode-stdio-1.0 main-is: Test.hs build-depends: describe, QuickCheck--
src/Data/Serialize/Descriptor.hs view
@@ -10,24 +10,24 @@ import Data.Serialize.Get import Data.Serialize.Put --- | 'Descriptor s a' is an applicative functor that describes the binary structure for a structure 's' while deserializing value 'a'.+-- | @Descriptor s a@ is an applicative functor that describes the binary structure for a structure 's' while deserializing value 'a'. newtype Descriptor s a = Descriptor { unwrapDescriptor :: (Get a, s -> Put) } --- | 'unwrapGet desc' takes a 'Descriptor' and returns only the internal 'Get' monad.+-- | @unwrapGet desc@ takes a 'Descriptor' and returns only the internal 'Get' monad. unwrapGet :: Descriptor s a -> Get a unwrapGet = fst . unwrapDescriptor --- | 'unwrapPut s desc' takes the structure being described and a 'Descriptor' for it, and returns the internal 'Put' monad.-unwrapPut :: s -> Descriptor s a -> Put+-- | @unwrapPut s desc@ takes the structure being described and a 'Descriptor' for it, and returns the internal 'Put' monad.+unwrapPut :: s -> Descriptor s a -> PutM () unwrapPut s = ($ s) . snd . unwrapDescriptor --- | Convenience function for 'runPut . unwrapPut s'+-- | Convenience function for @runPut . unwrapPut s@ serialize :: s -> Descriptor s a -> ByteString-serialize s = runPut . unwrapPut s+serialize s = snd . runPutM . unwrapPut s --- | Convenience function for 'flip runGet bs . unwrapGet'+-- | Convenience function for @flip runGet bs . unwrapGet@ deserialize :: ByteString -> Descriptor s s -> Either String s deserialize bs = flip runGet bs . unwrapGet @@ -38,3 +38,8 @@ pure a = Descriptor (pure a, \_ -> pure ()) (Descriptor (f, p)) <*> (Descriptor (g, p')) = Descriptor (f <*> g, \s' -> p s' >> p' s')++instance Monad (Descriptor s) where+ (Descriptor (g, p)) >>= f =+ Descriptor (g >>= fst . unwrapDescriptor . f, \s -> (p s <>) . ($ s) . snd . unwrapDescriptor . f $ undefined)+