-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Structure (hash) of your data types -- -- Calculate the hash of a data structure. It can be used as a magic -- number for the serialization formats. See binary-tagged for a -- binary bindings. @package structured @version 0.1.0.1 module Data.Structured.Internal type TypeName = String type ConstructorName = String -- | A sematic version of a data type. Usually 0. type TypeVersion = Word32 -- | Structure of a datatype. -- -- It can be infinite, as far as TypeReps involved are finite. -- (e.g. polymorphic recursion might cause troubles). data Structure -- | nominal, yet can be parametrised by other structures. Nominal :: !TypeRep -> !TypeVersion -> TypeName -> [Structure] -> Structure -- | a newtype wrapper Newtype :: !TypeRep -> !TypeVersion -> TypeName -> Structure -> Structure -- | sum-of-products structure Structure :: !TypeRep -> !TypeVersion -> TypeName -> SopStructure -> Structure type SopStructure = [(ConstructorName, [Structure])] -- | A MD5 hash digest of Structure. hashStructure :: Structure -> MD5 -- | A van-Laarhoven lens into TypeVersion of Structure -- --
--   typeVersion :: Lens' Structure TypeVersion
--   
typeVersion :: Functor f => (TypeVersion -> f TypeVersion) -> Structure -> f Structure -- | A van-Laarhoven lens into TypeName of Structure -- --
--   typeName :: Lens' Structure TypeName
--   
typeName :: Functor f => (TypeName -> f TypeName) -> Structure -> f Structure -- | Flatten Structure into something we can calculate hash of. -- -- As Structure can be potentially infinite. For mutually -- recursive types, we keep track of TypeReps, and put just -- TypeRep name when it's occurred another time. structureBuilder :: Structure -> Builder -- | Class of types with a known Structure. -- -- For regular data types Structured can be derived generically. -- --
--   data Record = Record { a :: Int, b :: Bool, c :: [Char] } deriving (Generic)
--   instance Structured Record
--   
class Typeable a => Structured a structure :: Structured a => Proxy a -> Structure structure :: (Structured a, Generic a, GStructured (Rep a)) => Proxy a -> Structure structureHash' :: Structured a => Tagged a MD5 -- | Semantically hashStructure . structure. structureHash :: forall a. Structured a => Proxy a -> MD5 -- | Use Typeable to infer name nominalStructure :: Typeable a => Proxy a -> Structure containerStructure :: forall f a. (Typeable f, Structured a) => Proxy (f a) -> Structure -- | Derive structure genrically. genericStructure :: forall a. (Typeable a, Generic a, GStructured (Rep a)) => Proxy a -> Structure -- | Used to implement genericStructure. class GStructured (f :: Type -> Type) gstructured :: GStructured f => TypeRep -> Proxy f -> TypeVersion -> Structure class GStructuredSum (f :: Type -> Type) gstructuredSum :: GStructuredSum f => Proxy f -> SopStructure -> SopStructure class GStructuredProd (f :: Type -> Type) gstructuredProd :: GStructuredProd f => Proxy f -> [Structure] -> [Structure] instance GHC.Generics.Generic Data.Structured.Internal.Structure instance GHC.Show.Show Data.Structured.Internal.Structure instance GHC.Classes.Ord Data.Structured.Internal.Structure instance GHC.Classes.Eq Data.Structured.Internal.Structure instance (i GHC.Types.~ GHC.Generics.C, GHC.Generics.Constructor c, Data.Structured.Internal.GStructuredProd f) => Data.Structured.Internal.GStructuredSum (GHC.Generics.M1 i c f) instance (i GHC.Types.~ GHC.Generics.S, Data.Structured.Internal.GStructuredProd f) => Data.Structured.Internal.GStructuredProd (GHC.Generics.M1 i c f) instance Data.Structured.Internal.Structured c => Data.Structured.Internal.GStructuredProd (GHC.Generics.K1 i c) instance Data.Structured.Internal.GStructuredProd GHC.Generics.U1 instance (Data.Structured.Internal.GStructuredProd f, Data.Structured.Internal.GStructuredProd g) => Data.Structured.Internal.GStructuredProd (f GHC.Generics.:*: g) instance (i GHC.Types.~ GHC.Generics.D, GHC.Generics.Datatype c, Data.Structured.Internal.GStructuredSum f) => Data.Structured.Internal.GStructured (GHC.Generics.M1 i c f) instance (Data.Structured.Internal.GStructuredSum f, Data.Structured.Internal.GStructuredSum g) => Data.Structured.Internal.GStructuredSum (f GHC.Generics.:+: g) instance Data.Structured.Internal.GStructuredSum GHC.Generics.V1 instance Data.Structured.Internal.Structured () instance Data.Structured.Internal.Structured GHC.Types.Bool instance Data.Structured.Internal.Structured GHC.Types.Ordering instance Data.Structured.Internal.Structured GHC.Types.Char instance (Data.Structured.Internal.Structured a, Data.Structured.Internal.Structured b) => Data.Structured.Internal.Structured (a -> b) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (GHC.Maybe.Maybe a) instance (Data.Structured.Internal.Structured a, Data.Structured.Internal.Structured b) => Data.Structured.Internal.Structured (Data.Either.Either a b) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (GHC.Real.Ratio a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured [a] instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (GHC.Base.NonEmpty a) instance (Data.Structured.Internal.Structured a1, Data.Structured.Internal.Structured a2) => Data.Structured.Internal.Structured (a1, a2) instance (Data.Structured.Internal.Structured a1, Data.Structured.Internal.Structured a2, Data.Structured.Internal.Structured a3) => Data.Structured.Internal.Structured (a1, a2, a3) instance (Data.Structured.Internal.Structured a1, Data.Structured.Internal.Structured a2, Data.Structured.Internal.Structured a3, Data.Structured.Internal.Structured a4) => Data.Structured.Internal.Structured (a1, a2, a3, a4) instance (Data.Structured.Internal.Structured a1, Data.Structured.Internal.Structured a2, Data.Structured.Internal.Structured a3, Data.Structured.Internal.Structured a4, Data.Structured.Internal.Structured a5) => Data.Structured.Internal.Structured (a1, a2, a3, a4, a5) instance (Data.Structured.Internal.Structured a1, Data.Structured.Internal.Structured a2, Data.Structured.Internal.Structured a3, Data.Structured.Internal.Structured a4, Data.Structured.Internal.Structured a5, Data.Structured.Internal.Structured a6) => Data.Structured.Internal.Structured (a1, a2, a3, a4, a5, a6) instance (Data.Structured.Internal.Structured a1, Data.Structured.Internal.Structured a2, Data.Structured.Internal.Structured a3, Data.Structured.Internal.Structured a4, Data.Structured.Internal.Structured a5, Data.Structured.Internal.Structured a6, Data.Structured.Internal.Structured a7) => Data.Structured.Internal.Structured (a1, a2, a3, a4, a5, a6, a7) instance Data.Structured.Internal.Structured GHC.Types.Int instance Data.Structured.Internal.Structured GHC.Integer.Type.Integer instance Data.Structured.Internal.Structured GHC.Types.Word instance Data.Structured.Internal.Structured GHC.Int.Int8 instance Data.Structured.Internal.Structured GHC.Int.Int16 instance Data.Structured.Internal.Structured GHC.Int.Int32 instance Data.Structured.Internal.Structured GHC.Int.Int64 instance Data.Structured.Internal.Structured GHC.Word.Word8 instance Data.Structured.Internal.Structured GHC.Word.Word16 instance Data.Structured.Internal.Structured GHC.Word.Word32 instance Data.Structured.Internal.Structured GHC.Word.Word64 instance Data.Structured.Internal.Structured GHC.Types.Float instance Data.Structured.Internal.Structured GHC.Types.Double instance forall k (a :: k). (Data.Typeable.Internal.Typeable k, Data.Typeable.Internal.Typeable a, Data.Fixed.HasResolution a) => Data.Structured.Internal.Structured (Data.Fixed.Fixed a) instance Data.Structured.Internal.Structured GHC.Natural.Natural instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.Min a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.Max a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.First a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.Last a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.WrappedMonoid a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Monoid.First a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Monoid.Last a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.Internal.Sum a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.Internal.Product a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.Internal.Dual a) instance Data.Structured.Internal.Structured a => Data.Structured.Internal.Structured (Data.Semigroup.Internal.Endo a) instance Data.Structured.Internal.Structured Data.Semigroup.Internal.All instance Data.Structured.Internal.Structured Data.Semigroup.Internal.Any instance Data.Structured.Internal.Structured Data.ByteString.Internal.ByteString instance Data.Structured.Internal.Structured Data.ByteString.Lazy.Internal.ByteString instance Data.Structured.Internal.Structured Data.ByteString.Short.Internal.ShortByteString instance Data.Structured.Internal.Structured Data.Text.Internal.Text instance Data.Structured.Internal.Structured Data.Text.Internal.Lazy.Text instance (Data.Structured.Internal.Structured k, Data.Structured.Internal.Structured v) => Data.Structured.Internal.Structured (Data.Map.Internal.Map k v) instance Data.Structured.Internal.Structured k => Data.Structured.Internal.Structured (Data.Set.Internal.Set k) instance Data.Structured.Internal.Structured v => Data.Structured.Internal.Structured (Data.IntMap.Internal.IntMap v) instance Data.Structured.Internal.Structured Data.IntSet.Internal.IntSet instance Data.Structured.Internal.Structured v => Data.Structured.Internal.Structured (Data.Sequence.Internal.Seq v) instance Data.Structured.Internal.Structured Data.Time.Clock.Internal.UTCTime.UTCTime instance Data.Structured.Internal.Structured Data.Time.Clock.Internal.DiffTime.DiffTime instance Data.Structured.Internal.Structured Data.Time.Clock.Internal.UniversalTime.UniversalTime instance Data.Structured.Internal.Structured Data.Time.Clock.Internal.NominalDiffTime.NominalDiffTime instance Data.Structured.Internal.Structured Data.Time.Calendar.Days.Day instance Data.Structured.Internal.Structured Data.Time.LocalTime.Internal.TimeZone.TimeZone instance Data.Structured.Internal.Structured Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay instance Data.Structured.Internal.Structured Data.Time.LocalTime.Internal.LocalTime.LocalTime instance Data.Structured.Internal.Structured Data.Time.Calendar.Week.DayOfWeek instance (Data.Structured.Internal.Structured i, Data.Structured.Internal.Structured e) => Data.Structured.Internal.Structured (GHC.Arr.Array i e) instance (Data.Structured.Internal.Structured i, Data.Structured.Internal.Structured e) => Data.Structured.Internal.Structured (Data.Array.Base.UArray i e) instance Data.Structured.Internal.Structured Data.Aeson.Types.Internal.Value instance (Data.Structured.Internal.Structured k, Data.Structured.Internal.Structured v) => Data.Structured.Internal.Structured (Data.HashMap.Internal.HashMap k v) instance Data.Structured.Internal.Structured k => Data.Structured.Internal.Structured (Data.HashSet.Internal.HashSet k) instance Data.Structured.Internal.Structured v => Data.Structured.Internal.Structured (Data.Vector.Vector v) instance Data.Structured.Internal.Structured v => Data.Structured.Internal.Structured (Data.Vector.Storable.Vector v) instance Data.Structured.Internal.Structured v => Data.Structured.Internal.Structured (Data.Vector.Unboxed.Base.Vector v) instance Data.Structured.Internal.Structured Data.Scientific.Scientific instance Data.Structured.Internal.Structured Data.UUID.Types.Internal.UUID instance Data.Structured.Internal.Structured Data.Version.Version instance forall k (b :: k) a. (Data.Typeable.Internal.Typeable k, Data.Typeable.Internal.Typeable b, Data.Structured.Internal.Structured a) => Data.Structured.Internal.Structured (Data.Tagged.Tagged b a) -- | Structurally tag data. -- -- See binary-tagged package taking use of this. Useful when -- most Binary instances are Generic derived. -- -- Say you have a data type -- --
--   data Record = Record
--     { _recordFields  :: HM.HashMap Text (Integer, ByteString)
--     , _recordEnabled :: Bool
--     }
--     deriving (Eq, Show, Generic)
--   
--   instance Binary Record
--   instance Structured Record
--   
-- -- then you can serialise and deserialise Record values with a -- structure tag by simply -- --
--   structuredEncode record :: LBS.ByteString
--   structuredDecode lbs    :: Either String Record
--   
-- -- If structure of Record changes in between, deserialisation -- will fail early. -- -- Technically, Structured is not related to Binary, and -- may be useful in other ways. module Data.Structured -- | Class of types with a known Structure. -- -- For regular data types Structured can be derived generically. -- --
--   data Record = Record { a :: Int, b :: Bool, c :: [Char] } deriving (Generic)
--   instance Structured Record
--   
class Typeable a => Structured a structure :: Structured a => Proxy a -> Structure structure :: (Structured a, Generic a, GStructured (Rep a)) => Proxy a -> Structure -- | Semantically hashStructure . structure. structureHash :: forall a. Structured a => Proxy a -> MD5 -- | Flatten Structure into something we can calculate hash of. -- -- As Structure can be potentially infinite. For mutually -- recursive types, we keep track of TypeReps, and put just -- TypeRep name when it's occurred another time. structureBuilder :: Structure -> Builder -- | Derive structure genrically. genericStructure :: forall a. (Typeable a, Generic a, GStructured (Rep a)) => Proxy a -> Structure -- | Used to implement genericStructure. class GStructured (f :: Type -> Type) -- | Use Typeable to infer name nominalStructure :: Typeable a => Proxy a -> Structure containerStructure :: forall f a. (Typeable f, Structured a) => Proxy (f a) -> Structure -- | Structure of a datatype. -- -- It can be infinite, as far as TypeReps involved are finite. -- (e.g. polymorphic recursion might cause troubles). data Structure -- | nominal, yet can be parametrised by other structures. Nominal :: !TypeRep -> !TypeVersion -> TypeName -> [Structure] -> Structure -- | a newtype wrapper Newtype :: !TypeRep -> !TypeVersion -> TypeName -> Structure -> Structure -- | sum-of-products structure Structure :: !TypeRep -> !TypeVersion -> TypeName -> SopStructure -> Structure type TypeName = String type ConstructorName = String -- | A sematic version of a data type. Usually 0. type TypeVersion = Word32 type SopStructure = [(ConstructorName, [Structure])] -- | A MD5 hash digest of Structure. hashStructure :: Structure -> MD5 -- | A van-Laarhoven lens into TypeVersion of Structure -- --
--   typeVersion :: Lens' Structure TypeVersion
--   
typeVersion :: Functor f => (TypeVersion -> f TypeVersion) -> Structure -> f Structure -- | A van-Laarhoven lens into TypeName of Structure -- --
--   typeName :: Lens' Structure TypeName
--   
typeName :: Functor f => (TypeName -> f TypeName) -> Structure -> f Structure type MD5 = Fingerprint -- | Show MD5 in human readable form -- --
--   >>> showMD5 (Fingerprint 123 456)
--   "000000000000007b00000000000001c8"
--   
-- --
--   >>> showMD5 $ md5 $ BS.pack [0..127]
--   "37eff01866ba3f538421b30b7cbefcac"
--   
-- -- @since 3.2.0.0 showMD5 :: MD5 -> String -- | @since 3.2.0.0 md5 :: ByteString -> MD5 -- |
--   >>> showMD5 $ md5FromInteger 0x37eff01866ba3f538421b30b7cbefcac
--   "37eff01866ba3f538421b30b7cbefcac"
--   
-- -- Note: the input is truncated: -- --
--   >>> showMD5 $ md5FromInteger 0x1230000037eff01866ba3f538421b30b7cbefcac
--   "37eff01866ba3f538421b30b7cbefcac"
--   
-- -- Yet, negative numbers are not a problem... -- --
--   >>> showMD5 $ md5FromInteger (-1)
--   "ffffffffffffffffffffffffffffffff"
--   
md5FromInteger :: Integer -> MD5