Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | Toralf Wittner <tw@dtex.org> |
Safe Haskell | Safe-Inferred |
Type-level restricted data.
This module allows for type declarations which embed certain restrictions,
such as value bounds. E.g. Restricted N0 N1 Int
denotes an Int
which can
only have values [0 .. 1]. When creating such a value, the constructor functions
restrict
or toRestricted
ensure that the restrictions are obeyed. Code
that consumes restricted types does not need to check the constraints.
N.B. This module is more or less tailored to be used within ZMQ3
.
Therefore the provided type level restrictions are limited.
- data Restricted l u v
- class Restriction l u v where
- toRestricted :: v -> Maybe (Restricted l u v)
- restrict :: v -> Restricted l u v
- rvalue :: Restricted l u v -> v
- data Nneg1
- data N1
- data N0
- data N254
- data Inf
Documentation
class Restriction l u v where
A uniform way to restrict values.
toRestricted :: v -> Maybe (Restricted l u v)
Create a restricted value. Returns Nothing
if
the given value does not satisfy all restrictions.
restrict :: v -> Restricted l u v
Create a restricted value. If the given value does not satisfy the restrictions, a modified variant is used instead, e.g. if an integer is larger than the upper bound, the upper bound value is used.
Integral a => Restriction N1 Int32 a | |
Integral a => Restriction N1 Int64 a | |
Integral a => Restriction N1 Inf a | |
Restriction N1 N254 String | |
Restriction N1 N254 ByteString | |
Integral a => Restriction N0 Int32 a | |
Integral a => Restriction N0 Int64 a | |
Integral a => Restriction N0 Inf a | |
Integral a => Restriction Nneg1 Int32 a | |
Integral a => Restriction Nneg1 Int64 a | |
Integral a => Restriction Nneg1 Inf a |
rvalue :: Restricted l u v -> v
Get the actual value.
data Nneg1
type level -1
Show Nneg1 | |
Integral a => Restriction Nneg1 Int32 a | |
Integral a => Restriction Nneg1 Int64 a | |
Integral a => Restriction Nneg1 Inf a |
data N1
type-level 1
Show N1 | |
Integral a => Restriction N1 Int32 a | |
Integral a => Restriction N1 Int64 a | |
Integral a => Restriction N1 Inf a | |
Restriction N1 N254 String | |
Restriction N1 N254 ByteString |
data N0
type-level 0
Show N0 | |
Integral a => Restriction N0 Int32 a | |
Integral a => Restriction N0 Int64 a | |
Integral a => Restriction N0 Inf a |
data Inf
type-level infinity
Show Inf | |
Integral a => Restriction N1 Inf a | |
Integral a => Restriction N0 Inf a | |
Integral a => Restriction Nneg1 Inf a |