Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Extensions |
|
Internals, exposed mostly for potential use by testsuites and benchmarks.
Not recommended to be used from within other independent libraries.
- data Typed a = Typed TypeInformation a
- data Typed' a = Typed' TypeInformation a
- data TypeInformation
- newtype Hash5 = Hash5 Word8
- mkHash5 :: Integral a => a -> Hash5
- newtype Hash32 = Hash32 Word32
- newtype Hash64 = Hash64 Word64
- typed :: Typeable a => TypeFormat -> a -> Typed a
- makeTypeInformation :: TypeFormat -> TypeRep -> TypeInformation
- data TypeFormat
- getFormat :: TypeInformation -> TypeFormat
- typecheck :: Typeable a => Typed a -> Either String (Typed a)
- typecheck' :: Typeable a => Typed' a -> Either String (Typed a)
- erase :: Typed a -> a
- preserialize :: TypeInformation -> TypeInformation
- data TypeRep = TypeRep TyCon [TypeRep]
- stripTypeRep :: TypeRep -> TypeRep
- unStripTypeRep :: TypeRep -> TypeRep
- hashType5 :: TypeRep -> Hash5
- hashed5Split :: Word8 -> (Word8, Hash5)
- hashType32 :: TypeRep -> Hash32
- hashType64 :: TypeRep -> Hash64
- data TyCon = TyCon String String String
- stripTyCon :: TyCon -> TyCon
- unStripTyCon :: TyCon -> TyCon
Typed
A value suitable to be typechecked using the contained extra type information.
Typed TypeInformation a | Using this data constructor directly is unsafe, as it allows
construction of ill-typed |
Like Typed
, but the type information is not checked. Useful to read type
and value, and do the typechecking externally, as required by the caching
of decodeTyped
. Using typecheck'
, this can be promoted
to a proper Typed
value.
data TypeInformation Source
Type information stored alongside a value to be serialized, so that the
recipient can do consistency checks. See TypeFormat
for more detailed
information on the fields.
A 5-bit hash value.
Since TypeInformation
needs 3 bit to store the sort of the
TypeInformation
, the remaining 5 bit per Word8
can be used to store a
hash value at no additional space cost. For this reason, it is important that
the three rightmost bits of any Hashed5
are set to zero, i.e. (
is .&.
7)id
on the contained Word8
.
This type intentionally doesn't have a Binary
instance, since its
serialization is part of the TypeInformation
Binary
instance exclusively.
mkHash5 :: Integral a => a -> Hash5 Source
Smart constructor for Hash5
values. Makes sure the rightmost three bits
are not set by applying a bit mask to the input.
A 32-bit hash value.
A 64-bit hash value.
typed :: Typeable a => TypeFormat -> a -> Typed a Source
makeTypeInformation :: TypeFormat -> TypeRep -> TypeInformation Source
Create the TypeInformation
to be stored inside a Typed
value from
a TypeRep
.
data TypeFormat Source
Different ways of including/verifying type information of serialized messages.
Untyped | Include no type information. |
Hashed5 | Like
|
Hashed32 | Compare types by their hash values (using the MurmurHash2 algorithm).
|
Hashed64 | Like |
Shown | Compare
|
Full | Compare the full representation of a data type.
|
getFormat :: TypeInformation -> TypeFormat Source
Extract which TypeFormat
was used to create a certain TypeInformation
.
If the type is Cached'
, then the contained information is assumed
well-formed. In the public API, this is safe to do, since only well-typed
Typed
values can be created in the first place.
typecheck :: Typeable a => Typed a -> Either String (Typed a) Source
Typecheck a Typed
. Returns the (well-typed) input, or an error message
if the types don't work out.
typecheck' :: Typeable a => Typed' a -> Either String (Typed a) Source
Typecheck a 'Typed\'' value so it can be used as a safe Typed
value.
preserialize :: TypeInformation -> TypeInformation Source
Sometimes it can be beneficial to serialize the type information in
advance, so that the maybe costly serialization step does not have to be
repeated on every invocation of encode
. Preserialization comes at a price
though, as the directly contained ByteString
requires its length to
be included in the final serialization, yielding a 8-byte overhead for the
required Int64
, and one for the tag of what was serialized
("shown or full?").
This function calculates the serialized version of TypeInformation
in
cases where the required 9 bytes are negligible (determined by an
arbitrary threshold, currently 10*9 bytes).
Used to make encodeTyped
more efficient; the source
there also makes a good usage example.
TypeRep
TypeRep
without the (internal) fingerprint.
stripTypeRep :: TypeRep -> TypeRep Source
Strip a TypeRep
off the fingerprint. Inverse of unStripTypeRep
.
unStripTypeRep :: TypeRep -> TypeRep Source
Add a fingerprint to a TypeRep
. Inverse of stripTypeRep
.
hashed5Split :: Word8 -> (Word8, Hash5) Source
Split a Word8
into the last 3 bit (used to tag the constructor) and
the first 5 (data payload). Used by the Binary
instance of
TypeInformation
.
hashType32 :: TypeRep -> Hash32 Source
Hash a TypeRep
to a 32-bit digest.
hashType64 :: TypeRep -> Hash64 Source
Hash a TypeRep
to a 64-bit digest.
TyCon
TyCon
without the (internal) fingerprint.
stripTyCon :: TyCon -> TyCon Source
Strip a TyCon
off the fingerprint. Inverse of unStripTyCon
.
unStripTyCon :: TyCon -> TyCon Source
Add a fingerprint to a TyCon
. Inverse of stripTyCon
.