| Safe Haskell | None |
|---|
Util.BinaryInstances
Description
Instances of the HasBinary class. This includes the
standard types (except of course for things like function types and
IO) plus a few others.
- data Choice5 v1 v2 v3 v4 v5
- class HasWrapper wrapper m where
- newtype Wrapped a = Wrapped {
- wrapped :: a
- data UnWrap m = forall val . HasBinary val m => UnWrap Byte val
- wrap0 :: Monad m => Byte -> wrapper -> Wrap wrapper m
- wrap1 :: HasBinary val m => Byte -> (val -> wrapper) -> Wrap wrapper m
- wrap2 :: HasBinary (val1, val2) m => Byte -> (val1 -> val2 -> wrapper) -> Wrap wrapper m
- wrap3 :: HasBinary (val1, val2, val3) m => Byte -> (val1 -> val2 -> val3 -> wrapper) -> Wrap wrapper m
- wrap4 :: HasBinary (val1, val2, val3, val4) m => Byte -> (val1 -> val2 -> val3 -> val4 -> wrapper) -> Wrap wrapper m
- newtype ReadShow a = ReadShow a
- newtype ViaEnum a = ViaEnum {
- enum :: a
- newtype Unsigned integral = Unsigned integral
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.
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.
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
Instances
| (Monad m, HasWrapper wrapper m) => HasBinary (Wrapped wrapper) m |
Value the HasWrapper instance generates from unWrap to
indicate how we should write some value to binary.
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.
Constructors
| ReadShow a |
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 |