tomland-1.3.3.3: Bidirectional TOML serialization
Copyright(c) 2018-2022 Kowainik
LicenseMPL-2.0
MaintainerKowainik <xrom.xkov@gmail.com>
StabilityStable
PortabilityPortable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Toml.Codec.Types

Description

Contains general underlying monad for bidirectional conversion.

Since: 1.3.0.0

Synopsis

Toml Codec

type TomlCodec a = Codec a a Source #

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 Source #

Immutable environment for TOML conversion.

Since: 1.3.0.0

Toml State

newtype TomlState a Source #

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

Instances

Instances details
Alternative TomlState Source #

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 Source #

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 Source #

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 Source #

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 Source #

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 Source #

Transform Either into TomlState.

Since: 1.3.0.0

Codec

data Codec i o Source #

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) Source # 
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) Source #

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) Source #

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 Source #

Alternative instance for function arrow but without empty.