Safe Haskell | None |
---|---|
Language | Haskell98 |
Instances of the HasBinary
class. This includes the
standard types (except of course for things like function types and
IO) plus a few others.
Synopsis
- data Choice5 v1 v2 v3 v4 v5
- class HasWrapper wrapper m where
- newtype Wrapped a = Wrapped {
- wrapped :: a
- data UnWrap m = 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.
Instances
(Eq v1, Eq v2, Eq v3, Eq v4, Eq v5) => Eq (Choice5 v1 v2 v3 v4 v5) Source # | |
(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 Source # | |
Defined in Util.BinaryInstances writeBin :: WriteBinary m -> Choice5 v1 v2 v3 v4 v5 -> m () Source # readBin :: ReadBinary m -> m (Choice5 v1 v2 v3 v4 v5) Source # |
class HasWrapper wrapper m where Source #
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 Source # | |
Defined in Util.BinaryInstances writeBin :: WriteBinary m -> Wrapped wrapper -> m () Source # readBin :: ReadBinary m -> m (Wrapped wrapper) Source # |
Value the HasWrapper
instance generates from unWrap
to
indicate how we should write some value to binary.
wrap0 :: Monad m => Byte -> wrapper -> Wrap wrapper m Source #
Wrap
value for constructor with no arguments.
wrap1 :: HasBinary val m => Byte -> (val -> wrapper) -> Wrap wrapper m Source #
Wrap
value for constructor with 1 argument.
wrap2 :: HasBinary (val1, val2) m => Byte -> (val1 -> val2 -> wrapper) -> Wrap wrapper m Source #
Wrap
value for constructor with 2 arguments.
wrap3 :: HasBinary (val1, val2, val3) m => Byte -> (val1 -> val2 -> val3 -> wrapper) -> Wrap wrapper m Source #
Wrap
value for constructor with 3 arguments.
wrap4 :: HasBinary (val1, val2, val3, val4) m => Byte -> (val1 -> val2 -> val3 -> val4 -> wrapper) -> Wrap wrapper m Source #
Wrap
value for constructor with 4 arguments.
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.
Unsigned integral |