HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduletomland-1.3.3.3Haskell2010

Toml.Codec.Types

SPDX-License-Identifier : MPL-2.0 Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Contains general underlying monad for bidirectional conversion.

  • 4 types
  • 2 values
  • Packagetomland-1.3.3.3
  • Exports6
  • LanguageHaskell2010
  • LicenceMPL-2.0
  • SourceTypes.hs

Toml Codec

1 declaration
typetype TomlCodec a = Codec a a
#

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

Toml Environment

1 declaration

Toml State

2 declarations
newtypenewtype 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)

Constructors

Instances5Monad, Functor, Applicative, Alternative, MonadState

Codec

1 declaration
datadata 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.

Constructors

  • Codec
    • 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.

Instances3Functor, Applicative, Alternative

Function alternative

1 declaration
value(<!>) :: Alternative f => (a -> f x) -> (a -> f x) -> a -> f x
#

Alternative instance for function arrow but without empty.