HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

ModuleCabal-syntax-3.18.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.

Contents
  1. Encoding and decoding
  2. Structured class
  3. Structure type
Synopsis

Encoding and decoding

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

Structured class

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

Instances139Structured, …

Structure type

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.18.1.0 · Distribution.Utils.Structured