Copyright | (c) 2018-2022 Kowainik |
---|---|
License | MPL-2.0 |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Stability | Stable |
Portability | Portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Contains general underlying monad for bidirectional conversion.
Since: 1.3.0.0
Synopsis
- type TomlCodec a = Codec a a
- type TomlEnv a = TOML -> Validation [TomlDecodeError] a
- newtype TomlState a = TomlState {
- unTomlState :: TOML -> (Maybe a, TOML)
- eitherToTomlState :: Either e a -> TomlState a
- data Codec i o = Codec {
- codecRead :: TomlEnv o
- codecWrite :: i -> TomlState o
- (<!>) :: Alternative f => (a -> f x) -> (a -> f x) -> a -> f x
Toml Codec
Toml Environment
type TomlEnv a = TOML -> Validation [TomlDecodeError] a Source #
Immutable environment for TOML conversion.
Since: 1.3.0.0
Toml State
Mutable context for TOML conversion.
We are introducing our own implemetation of state with MonadState
instance due
to some limitation in the design connected to the usage of State.
This newtype is equivalent to the following transformer:
MaybeT (State TOML)
Since: 1.3.0.0
TomlState | |
|
eitherToTomlState :: Either e a -> TomlState a Source #
Codec
Monad for bidirectional conversion. Contains pair of functions:
- How to read value of type
o
(out) from immutable environment context (TomlEnv
)? - How to store a value of type
i
(in) in stateful context (TomlState
) and return a value of typeo
?
This approach with the bunch of utility functions allows to
have single description for from/to TOML
conversion.
In practice this type will always be used in the following way:
typeTomlCodec
a =Codec
a a
Type parameter i
if fictional. Here some trick is used. This trick is
implemented in the codec package and
described in more details in related blog post:
https://blog.poisson.chat/posts/2016-10-12-bidirectional-serialization.html.
Since: 0.0.0
Codec | |
|
Function alternative
(<!>) :: Alternative f => (a -> f x) -> (a -> f x) -> a -> f x infixl 3 Source #
Alternative instance for function arrow but without empty
.