tomland-1.3.3.3: Bidirectional TOML serialization

Copyright | (c) 2018-2022 Kowainik
License | MPL-2.0
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | None
Language | Haskell2010

Toml.Codec.Types

Contents

- Toml Codec
- Toml Environment
- Toml State
- Codec
- Function alternative

Description

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

type TomlCodec a = Codec a a #

Specialied `Codec` type alias for bidirectional TOML serialization. Keeps `TOML` object as both environment and state.

Since: 0.5.0

# Toml Environment

type TomlEnv a = TOML -> Validation [TomlDecodeError] a #

Immutable environment for TOML conversion.

Since: 1.3.0.0

# Toml State

newtype TomlState a #

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

Constructors

TomlState |
Fields unTomlState :: TOML -> (Maybe a, TOML)

#### Instances

Instances details

Alternative TomlState # | Since: 1.3.0.0
Instance details Defined in Toml.Codec.Types Methods empty :: TomlState a # (<|>) :: TomlState a -> TomlState a -> TomlState a # some :: TomlState a -> TomlState [a] # many :: TomlState a -> TomlState [a] #
Applicative TomlState # | Since: 1.3.0.0
Instance details Defined in Toml.Codec.Types Methods pure :: a -> TomlState a # (<*>) :: TomlState (a -> b) -> TomlState a -> TomlState b # liftA2 :: (a -> b -> c) -> TomlState a -> TomlState b -> TomlState c # (*>) :: TomlState a -> TomlState b -> TomlState b # (<*) :: TomlState a -> TomlState b -> TomlState a #
Functor TomlState # | Since: 1.3.0.0
Instance details Defined in Toml.Codec.Types Methods fmap :: (a -> b) -> TomlState a -> TomlState b # (<$) :: a -> TomlState b -> TomlState a #
Monad TomlState # | Since: 1.3.0.0
Instance details Defined in Toml.Codec.Types Methods (>>=) :: TomlState a -> (a -> TomlState b) -> TomlState b # (>>) :: TomlState a -> TomlState b -> TomlState b # return :: a -> TomlState a #
s ~ TOML => MonadState s TomlState # | Since: 1.3.0.0
Instance details Defined in Toml.Codec.Types Methods get :: TomlState s # put :: s -> TomlState () # state :: (s -> (a, s)) -> TomlState a #

eitherToTomlState :: Either e a -> TomlState a #

Transform `Either` into `TomlState`.

Since: 1.3.0.0

# Codec

data Codec i o #

Monad for bidirectional conversion. Contains pair of functions:

1. How to read value of type `o` (out) from immutable environment context (`TomlEnv`)?
2. How to store a value of type `i` (in) in stateful context (`TomlState`) and return a value of type `o`?

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:

    type TomlCodec 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

Constructors

Codec |
Fields codecRead :: TomlEnv o Extract value of type `o` from monadic context `TomlEnv`. codecWrite :: i -> TomlState o Store value of type `i` inside monadic context `TomlState` and returning value of type `o`. Type of this function actually should be `o -> TomlState ()` but with such type it's impossible to have `Monad` and other instances.

#### Instances

Instances details

Alternative (Codec i) # |
Instance details Defined in Toml.Codec.Types Methods empty :: Codec i a # (<|>) :: Codec i a -> Codec i a -> Codec i a # some :: Codec i a -> Codec i [a] # many :: Codec i a -> Codec i [a] #
Applicative (Codec i) # | Since: 0.0.0
Instance details Defined in Toml.Codec.Types Methods pure :: a -> Codec i a # (<*>) :: Codec i (a -> b) -> Codec i a -> Codec i b # liftA2 :: (a -> b -> c) -> Codec i a -> Codec i b -> Codec i c # (*>) :: Codec i a -> Codec i b -> Codec i b # (<*) :: Codec i a -> Codec i b -> Codec i a #
Functor (Codec i) # | Since: 0.0.0
Instance details Defined in Toml.Codec.Types Methods fmap :: (a -> b) -> Codec i a -> Codec i b # (<$) :: a -> Codec i b -> Codec i a #

# Function alternative

(<!>) :: Alternative f => (a -> f x) -> (a -> f x) -> a -> f x infixl 3 #

Alternative instance for function arrow but without `empty`.