uni-util-2.2.1.0: Utilities for the uniform workbench

Util.BinaryInstances

Description

Instances of the Binary.HasBinary class. This includes the standard types (except of course for things like function types and IO) plus a few others.

Synopsis

Documentation

data Choice5 v1 v2 v3 v4 v5 Source

This is a rather inelegant way of encoding a type with up to 5 alternatives. If 5 is too many, use () for the others, if too few use HasWrapper. In fact HasWrapper is probably better anyway.

Constructors

Choice1 v1 
Choice2 v2 
Choice3 v3 
Choice4 v4 
Choice5 v5 

Instances

(Eq v1, Eq v2, Eq v3, Eq v4, Eq v5) => Eq (Choice5 v1 v2 v3 v4 v5) 
(Monad m, HasBinary v1 m, HasBinary v2 m, HasBinary v3 m, HasBinary v4 m, HasBinary v5 m) => HasBinary (Choice5 v1 v2 v3 v4 v5) m 

class HasWrapper wrapper m whereSource

A class allowing you to handle types with up to 256 alternatives. If this all seems to complicated, look at the source file and the example for the "Tree" data type.

Methods

wrapsSource

Arguments

:: [Wrap wrapper m]

For each alternative in the type, provide a recognition Byte, and a way of mapping that alternative to the (wrapper)

unWrapSource

Arguments

:: wrapper 
-> UnWrap m

Map a (wrapper) to the corresponding recognition Byte and the type within the alternative.

Instances

(Monad m, HasBinary val m) => HasWrapper (Tree val) m 

newtype Wrapped a Source

Newtype alias you need to wrap around something which instances HasWrapper to get an actual HasBinary instance. You will then need something like this:

 instance Monad m => HasBinary a m where
   writeBin = mapWrite Wrapped
   readBin = mapRead wrapped

Constructors

Wrapped 

Fields

wrapped :: a
 

Instances

(Monad m, HasWrapper wrapper m) => HasBinary (Wrapped wrapper) m 

data UnWrap m Source

Value the HasWrapper instance generates from unWrap to indicate how we should write some value to binary.

Constructors

forall val . HasBinary val m => UnWrap Byte val 

wrap0 :: Monad m => Byte -> wrapper -> Wrap wrapper mSource

Wrap value for constructor with no arguments.

wrap1 :: HasBinary val m => Byte -> (val -> wrapper) -> Wrap wrapper mSource

Wrap value for constructor with 1 argument.

wrap2 :: HasBinary (val1, val2) m => Byte -> (val1 -> val2 -> wrapper) -> Wrap wrapper mSource

Wrap value for constructor with 2 arguments.

wrap3 :: HasBinary (val1, val2, val3) m => Byte -> (val1 -> val2 -> val3 -> wrapper) -> Wrap wrapper mSource

Wrap value for constructor with 3 arguments.

wrap4 :: HasBinary (val1, val2, val3, val4) m => Byte -> (val1 -> val2 -> val3 -> val4 -> wrapper) -> Wrap wrapper mSource

Wrap value for constructor with 4 arguments.

newtype ReadShow a Source

Newtype alias for things we want to encode or decode via their Read or Show String representation.

Constructors

ReadShow a 

Instances

(Read a, Show a, Monad m) => HasBinary (ReadShow a) m 

newtype ViaEnum a Source

Constructors

ViaEnum 

Fields

enum :: a
 

Instances

(Monad m, Enum a) => HasBinary (ViaEnum a) m 

newtype Unsigned integral Source

This is an newtype alias for integral types where the user promises that the value will be non-negative, and so saves us a bit. This is what we use for character data incidentally, so that ASCII characters with codes <128 can be encoded (as themselves) in just one byte.

Constructors

Unsigned integral 

Instances

(Monad m, Integral integral, Bits integral) => HasBinary (Unsigned integral) m