bindynamic-1.0.0.0: A variation of Data.Dynamic.Dynamic with a Binary instance

Safe HaskellNone
LanguageHaskell2010

Data.Dynamic.Binary

Contents

Description

Provides a data type similar to Dynamic from base:Data.Dynamic, but with a Binary instance. This of course means that only instances of Binary can be encapsulated in this Dynamic.

Synopsis

The Dynamic type

data Dynamic Source

This Dynamic is a variant of the Dynamic from base:Data.Dynamic with a Binary instance. It encapsulates a value of an arbitrary type, provided that the type is instance of both Typeable and Binary.

The advantage over just using a ByteString is the type safety: Raw ByteStrings have no associated type, and the Binary interface makes no guarantee that the representations for values of different types are different.

The advantage over using a type-tagged ByteString is that Dynamic avoids unnecessary encoding/decoding by internally containing either a ByteString or a decoded value.

Converting to and from Dynamic

toDyn :: (Typeable a, Binary a) => a -> Dynamic Source

Converts an arbitrary value into an object of type Dynamic.

fromDyn Source

Arguments

:: (Typeable a, Binary a) 
=> Dynamic 
-> a

default value

-> a

if types match, the value contained in the Dynamic, otherwise the default value.

Converts a Dynamic object back into an ordinary Haskell value of the correct type.

fromDynamic Source

Arguments

:: (Typeable a, Binary a) 
=> Dynamic 
-> Maybe a

if types match, Just the contained value, otherwise Nothing.

Converts a Dynamic object back into an ordinary Haskell value of the correct type.

Accessor for the contained TypeRep

dynTypeRep :: Dynamic -> TypeRep Source

Getter for the TypeRep of this Dynamic.