binary-instances-1.0.6/0000755000000000000000000000000007346545000013160 5ustar0000000000000000binary-instances-1.0.6/CHANGELOG.md0000644000000000000000000000301507346545000014770 0ustar0000000000000000## 1.0.6 - Support GHC-9.12.1 - Fix a small bug QuarterOfYear instance ## 1.0.5 - Support GHC-8.6.5...9.10.1 ## 1.0.4 - Add instances for `ByteArray` from `data-array-byte` or `base` - Support `primitive-0.8` - Support `tagged-0.8.7` ## 1.0.3 - Add instance for `primitive`s `ByteArray`. ## 1.0.2 - Support `aeson-2.0.0.0` ## 1.0.1 - Add instances for `time-1.11` types: `Month`, `Quarter`, `QuarterOfYear` ## 1 - **Breaking change** rename this package to `binary-instances`. It was previously known as `binary-orphans`, which is now only a subset. - Depend on [`time-compat`](http://hackage.haskell.org/package/time-compat) to provide `Binary` instances for `time` types. ## 0.1.8.0 - `ZonedTime` instance (by @mstksg) ## 0.1.7.0 - GHC-8.2 support - `SystemTime` instance (`time-1.8`) ## 0.1.6.0 - Add instance for `hashed` in `hashable >=1.2.5.0` ## 0.1.5.2 - Fix issue with binary-0.5.x ## 0.1.5.1 - Fix issue with binary-0.8.4.x and GHC-7.x ## 0.1.5.0 - Add `CI a` instance - Add `Alt f a` instance for `base >= 4.8.0.0` - Add `WrappedMonoid m` and `Arg a b` instances - Support `binary-0.8.4.0` - Add `Void` instance (`base <4.8`) - Add `Natural` instance (`nats <1.1`, `base <4.8`) ## 0.1.4.0 - Add `AbsoluteTime` instance (thanks @neongreen) ## 0.1.3.1 - Support GHC 7.6 ## 0.1.3.0 - Add `Min`, `Max`, `First`, `Last`, `Option`, and `NonEmpty` instances (from `semigroups`) ## 0.1.2.0 - Support `scientific >= 0.3.4` ## 0.1.1.0 - Add `Dual`, `All`, `Any`, `Sum`, `Product`, `First` and `Last` instances binary-instances-1.0.6/LICENSE0000644000000000000000000000276207346545000014174 0ustar0000000000000000Copyright (c) 2015, Oleg Grenrus All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Oleg Grenrus nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. binary-instances-1.0.6/Setup.hs0000644000000000000000000000005607346545000014615 0ustar0000000000000000import Distribution.Simple main = defaultMain binary-instances-1.0.6/binary-instances.cabal0000644000000000000000000000521107346545000017414 0ustar0000000000000000cabal-version: 2.2 name: binary-instances version: 1.0.6 synopsis: Orphan instances for binary description: `binary-instances` defines orphan instances for types in some popular packages. category: Web homepage: https://github.com/haskellari/binary-instances#readme bug-reports: https://github.com/haskellari/binary-instances/issues author: Oleg Grenrus maintainer: Oleg Grenrus license: BSD-3-Clause license-file: LICENSE build-type: Simple tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.6 || ==9.8.4 || ==9.10.1 || ==9.12.2 extra-source-files: CHANGELOG.md source-repository head type: git location: https://github.com/haskellari/binary-instances library default-language: Haskell2010 hs-source-dirs: src build-depends: , base >=4.6.0.1 && <4.22 , binary >=0.5.1.1 && <0.8.10 , text >=1.2.3.0 && <1.3 || >=2.0 && <2.2 build-depends: , case-insensitive >=1.2.1.0 && <1.2.2 , tagged >=0.8.8 && <0.8.10 build-depends: , aeson ^>=2.2.2.0 , binary-orphans ^>=1.0.5 , hashable ^>=1.4.4.0 || ^>=1.5.0.0 , primitive ^>=0.9.0.0 , scientific ^>=0.3.8.0 , time-compat ^>=1.9.7 , unordered-containers ^>=0.2.20 , vector ^>=0.13.1.0 , vector-binary-instances ^>=0.2.5.2 exposed-modules: Data.Binary.Instances Data.Binary.Instances.Aeson Data.Binary.Instances.CaseInsensitive Data.Binary.Instances.Hashable Data.Binary.Instances.Primitive Data.Binary.Instances.Scientific Data.Binary.Instances.Tagged Data.Binary.Instances.Text Data.Binary.Instances.Time Data.Binary.Instances.UnorderedContainers Data.Binary.Instances.Vector test-suite binary-instances-test default-language: Haskell2010 type: exitcode-stdio-1.0 main-is: Tests.hs hs-source-dirs: test ghc-options: -Wall -fno-warn-orphans build-depends: , aeson , base , binary , binary-instances , bytestring , case-insensitive , hashable , primitive , QuickCheck ^>=2.14.3 || ^>=2.15.0.1 , quickcheck-instances ^>=0.3.31 , scientific , tagged , tasty ^>=1.5 , tasty-quickcheck ^>=0.10.3 || ^>=0.11 , text , time-compat , unordered-containers , vector if impl(ghc >=8.0 && <9.4) build-depends: data-array-byte binary-instances-1.0.6/src/Data/Binary/0000755000000000000000000000000007346545000016044 5ustar0000000000000000binary-instances-1.0.6/src/Data/Binary/Instances.hs0000644000000000000000000000232207346545000020326 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE PolyKinds #-} {-# OPTIONS_GHC -fno-warn-orphans -fno-warn-unused-imports #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Binary.Orphans -- Copyright : (C) 2015-2019 Oleg Grenrus -- License : BSD-3-Clause -- Maintainer : Oleg Grenrus -- -- Provides orphan 'Binary' instances for types in various packages: -- -- * aeson -- * case-insensitive -- * hashable -- * scientific (prior to scientific-0.3.4.0) -- * tagged -- * text (through text-binary, or text >= 1.2.1) -- * time -- * unordered-containers -- * vector (through vector-binary-instances) -- module Data.Binary.Instances () where import Data.Binary.Orphans () import Data.Binary.Instances.Aeson () import Data.Binary.Instances.CaseInsensitive () import Data.Binary.Instances.Hashable () import Data.Binary.Instances.Primitive () import Data.Binary.Instances.Scientific () import Data.Binary.Instances.Tagged () import Data.Binary.Instances.Text () import Data.Binary.Instances.Time () import Data.Binary.Instances.UnorderedContainers () import Data.Binary.Instances.Vector () binary-instances-1.0.6/src/Data/Binary/Instances/0000755000000000000000000000000007346545000017773 5ustar0000000000000000binary-instances-1.0.6/src/Data/Binary/Instances/Aeson.hs0000644000000000000000000000237307346545000021401 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.Aeson where import Data.Binary (Binary, Get, get, put) import Data.Binary.Orphans () import Data.Binary.Instances.Scientific () import Data.Binary.Instances.Text () import Data.Binary.Instances.UnorderedContainers () import Data.Binary.Instances.Vector () import qualified Data.Aeson as A import qualified Data.Aeson.Key as Key import qualified Data.Aeson.KeyMap as KM instance Binary A.Value where get = do t <- get :: Get Int case t of 0 -> fmap A.Object get 1 -> fmap A.Array get 2 -> fmap A.String get 3 -> fmap A.Number get 4 -> fmap A.Bool get 5 -> return A.Null _ -> fail $ "Invalid Value tag: " ++ show t put (A.Object v) = put (0 :: Int) >> put v put (A.Array v) = put (1 :: Int) >> put v put (A.String v) = put (2 :: Int) >> put v put (A.Number v) = put (3 :: Int) >> put v put (A.Bool v) = put (4 :: Int) >> put v put A.Null = put (5 :: Int) instance Binary Key.Key where get = Key.fromText <$> get put = put . Key.toText instance Binary v => Binary (KM.KeyMap v) where get = fmap KM.fromList get put = put . KM.toList binary-instances-1.0.6/src/Data/Binary/Instances/CaseInsensitive.hs0000644000000000000000000000051007346545000023417 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.CaseInsensitive where import Data.Binary (Binary, get, put) import Data.Binary.Orphans () import qualified Data.CaseInsensitive as CI instance (CI.FoldCase a, Binary a) => Binary (CI.CI a) where get = fmap CI.mk get put = put . CI.foldedCase binary-instances-1.0.6/src/Data/Binary/Instances/Hashable.hs0000644000000000000000000000054207346545000022037 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.Hashable where import Data.Binary.Orphans () import Data.Binary (Binary, get, put) import qualified Data.Hashable as Hashable instance (Hashable.Hashable a, Binary a) => Binary (Hashable.Hashed a) where get = fmap Hashable.hashed get put = put . Hashable.unhashed binary-instances-1.0.6/src/Data/Binary/Instances/Primitive.hs0000644000000000000000000000016207346545000022276 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.Primitive where import Data.Binary.Orphans () binary-instances-1.0.6/src/Data/Binary/Instances/Scientific.hs0000644000000000000000000000016307346545000022407 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.Scientific where import Data.Binary.Orphans () binary-instances-1.0.6/src/Data/Binary/Instances/Tagged.hs0000644000000000000000000000063107346545000021522 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif module Data.Binary.Instances.Tagged where import Data.Binary (Binary, get, put) import Data.Binary.Orphans () import qualified Data.Tagged as Tagged instance Binary b => Binary (Tagged.Tagged s b) where put = put . Tagged.unTagged get = fmap Tagged.Tagged get binary-instances-1.0.6/src/Data/Binary/Instances/Text.hs0000644000000000000000000000020207346545000021245 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.Text where import Data.Binary.Orphans () binary-instances-1.0.6/src/Data/Binary/Instances/Time.hs0000644000000000000000000000723007346545000021227 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.Time where import Control.Monad (liftM2, liftM3) import Data.Binary (Binary, Get, Put, get, put) import Data.Binary.Orphans () import Data.Word (Word8) import qualified Data.Fixed as Fixed import qualified Data.Time.Calendar.Compat as Time import qualified Data.Time.Calendar.Month.Compat as Time import qualified Data.Time.Calendar.Quarter.Compat as Time import qualified Data.Time.Clock.Compat as Time import qualified Data.Time.Clock.System.Compat as Time import qualified Data.Time.Clock.TAI.Compat as Time import qualified Data.Time.LocalTime.Compat as Time instance Binary Time.Day where get = fmap Time.ModifiedJulianDay get put = put . Time.toModifiedJulianDay instance Binary Time.UniversalTime where get = fmap Time.ModJulianDate get put = put . Time.getModJulianDate instance Binary Time.DiffTime where get = fmap Time.picosecondsToDiffTime get put = (put :: Fixed.Pico -> Put) . realToFrac instance Binary Time.UTCTime where get = liftM2 Time.UTCTime get get put (Time.UTCTime d dt) = put d >> put dt instance Binary Time.NominalDiffTime where get = fmap realToFrac (get :: Get Fixed.Pico) put = (put :: Fixed.Pico -> Put) . realToFrac instance Binary Time.TimeZone where get = liftM3 Time.TimeZone get get get put (Time.TimeZone m s n) = put m >> put s >> put n instance Binary Time.TimeOfDay where get = liftM3 Time.TimeOfDay get get get put (Time.TimeOfDay h m s) = put h >> put m >> put s instance Binary Time.LocalTime where get = liftM2 Time.LocalTime get get put (Time.LocalTime d tod) = put d >> put tod instance Binary Time.ZonedTime where get = liftM2 Time.ZonedTime get get put (Time.ZonedTime t z) = put t >> put z instance Binary Time.AbsoluteTime where get = fmap (flip Time.addAbsoluteTime Time.taiEpoch) get put = put . flip Time.diffAbsoluteTime Time.taiEpoch instance Binary Time.SystemTime where get = liftM2 Time.MkSystemTime get get put (Time.MkSystemTime s ns) = put s >> put ns instance Binary Time.CalendarDiffDays where get = liftM2 Time.CalendarDiffDays get get put (Time.CalendarDiffDays m d) = put m >> put d instance Binary Time.CalendarDiffTime where get = liftM2 Time.CalendarDiffTime get get put (Time.CalendarDiffTime m nt) = put m >> put nt instance Binary Time.DayOfWeek where put Time.Sunday = put (0 :: Word8) put Time.Monday = put (1 :: Word8) put Time.Tuesday = put (2 :: Word8) put Time.Wednesday = put (3 :: Word8) put Time.Thursday = put (4 :: Word8) put Time.Friday = put (5 :: Word8) put Time.Saturday = put (6 :: Word8) get = do i <- get return $ case mod (i :: Word8) 7 of 0 -> Time.Sunday 1 -> Time.Monday 2 -> Time.Tuesday 3 -> Time.Wednesday 4 -> Time.Thursday 5 -> Time.Friday 6 -> Time.Saturday j -> error $ "panic: get @DayOfWeek: " ++ show (i, j) instance Binary Time.Month where put (Time.MkMonth m) = put m get = fmap Time.MkMonth get instance Binary Time.Quarter where put (Time.MkQuarter m) = put m get = fmap Time.MkQuarter get instance Binary Time.QuarterOfYear where put Time.Q1 = put (1 :: Word8) put Time.Q2 = put (2 :: Word8) put Time.Q3 = put (3 :: Word8) put Time.Q4 = put (4 :: Word8) get = do i <- get return $ case mod (i :: Word8) 4 of 1 -> Time.Q1 2 -> Time.Q2 3 -> Time.Q3 0 -> Time.Q4 j -> error $ "panic: get @QuarterOfYear: " ++ show (i, j) binary-instances-1.0.6/src/Data/Binary/Instances/UnorderedContainers.hs0000644000000000000000000000111107346545000024276 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.UnorderedContainers where import Data.Binary (Binary, get, put) import Data.Binary.Orphans () import qualified Data.Hashable as Hashable import qualified Data.HashMap.Lazy as HM import qualified Data.HashSet as HS instance (Hashable.Hashable k, Eq k, Binary k, Binary v) => Binary (HM.HashMap k v) where get = fmap HM.fromList get put = put . HM.toList instance (Hashable.Hashable v, Eq v, Binary v) => Binary (HS.HashSet v) where get = fmap HS.fromList get put = put . HS.toList binary-instances-1.0.6/src/Data/Binary/Instances/Vector.hs0000644000000000000000000000021407346545000021566 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Binary.Instances.Vector where import Data.Binary.Orphans () import Data.Vector.Binary () binary-instances-1.0.6/test/0000755000000000000000000000000007346545000014137 5ustar0000000000000000binary-instances-1.0.6/test/Tests.hs0000644000000000000000000000651007346545000015577 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE ScopedTypeVariables #-} module Main (main) where import Data.Binary.Instances () import Test.QuickCheck.Instances () import Data.Binary (Binary, decode, encode) import Data.Typeable (Typeable, typeOf) import Test.QuickCheck (Arbitrary, Property, (===)) import Test.Tasty (TestTree, defaultMain, testGroup) import Test.Tasty.QuickCheck (testProperty) import Data.ByteString (ByteString) import Data.CaseInsensitive (CI) import Data.HashMap.Lazy (HashMap) import Data.HashSet (HashSet) import Data.Monoid (Sum) import Data.Scientific (Scientific) import Data.Tagged (Tagged) import Data.Text (Text) import Data.Vector (Vector) import qualified Data.Vector.Unboxed as VU import qualified Data.Primitive as Prim import qualified Data.Time.Calendar.Compat as Time import qualified Data.Time.Calendar.Month.Compat as Time import qualified Data.Time.Calendar.Quarter.Compat as Time import qualified Data.Time.Clock.Compat as Time import qualified Data.Time.Clock.System.Compat as Time import qualified Data.Time.Clock.TAI.Compat as Time import qualified Data.Time.LocalTime.Compat as Time #if MIN_VERSION_base(4,9,0) import qualified Data.Array.Byte as AB #endif main :: IO () main = defaultMain tests tests :: TestTree tests = testGroup "Roundtrip" -- unordered containers [ roundtripProperty (undefined :: (HashMap Int String)) , roundtripProperty (undefined :: (HashSet Int)) -- time , roundtripProperty (undefined :: Time.AbsoluteTime) , roundtripProperty (undefined :: Time.CalendarDiffDays) , roundtripProperty (undefined :: Time.CalendarDiffTime) , roundtripProperty (undefined :: Time.Day) , roundtripProperty (undefined :: Time.DayOfWeek) , roundtripProperty (undefined :: Time.DiffTime) , roundtripProperty (undefined :: Time.LocalTime) , roundtripProperty (undefined :: Time.NominalDiffTime) , roundtripProperty (undefined :: Time.SystemTime) , roundtripProperty (undefined :: Time.TimeOfDay) , roundtripProperty (undefined :: Time.TimeZone) , roundtripProperty (undefined :: Time.UTCTime) , roundtripProperty (undefined :: Time.QuarterOfYear) , roundtripProperty (undefined :: Time.Quarter) , roundtripProperty (undefined :: Time.Month) -- case-insensitive & text #if __GLASGOW_HASKELL__ <807 -- https://github.com/haskell/text/issues/227 , roundtripProperty (undefined :: (CI Text)) #endif , roundtripProperty (undefined :: (CI ByteString)) -- semigroups / monoids , roundtripProperty (undefined :: (Sum Int)) -- tagged , roundtripProperty (undefined :: Tagged Int Char) -- scientific , roundtripProperty (undefined :: Scientific) -- vector , roundtripProperty (undefined :: Vector Char) , roundtripProperty (undefined :: VU.Vector Char) , roundtripProperty (undefined :: Prim.ByteArray) #if MIN_VERSION_base(4,9,0) , roundtripProperty (undefined :: AB.ByteArray) #endif ] roundtrip :: (Eq a, Show a, Binary a) => a -> a -> Property roundtrip _ x = x === decode (encode x) roundtripProperty :: forall a. (Eq a, Show a, Binary a, Arbitrary a, Typeable a) => a -> TestTree roundtripProperty x = testProperty (show (typeOf x)) $ roundtrip x