HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

ModuleCabal-syntax-3.12.1.0Haskell2010

Distribution.Utils.Structured

Structurally tag binary serialisation stream. 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 :: ByteString
structuredDecode lbs :: IO 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 uses.

  • 7 types
  • 2 classes
  • 13 values

Encoding and decoding

5 declarations

These functions operate like binary's counterparts, but the serialised version has a structure hash in front.

Structured class

8 declarations
classclass Typeable a => Structured a where
#

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

Methods

Instances134Structured, …

Structure type

9 declarations
datadata Structure
#

Structure of a datatype.

It can be infinite, as far as TypeReps involved are finite. (e.g. polymorphic recursion might cause troubles).

Constructors

Instances5Eq, Ord, Show, Generic, Rep
datadata Tag (a :: k)
#
Instances1Binary
  • Structured a => Binary (Tag a)Defined in Cabal-syntax-3.12.1.0 · Distribution.Utils.Structured