Toml.Schema.Generic.FromValue

toml-parser-2.0.1.0: TOML 1.0.0 parser

Copyright | (c) Eric Mertens 2023
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Toml.Schema.Generic.FromValue

Contents

- Record from table
- Product type from array

Description

Generic implementations of matching tables and arrays.

Synopsis

- class GParseTable (f :: Type -> Type) where
  - gParseTable :: ParseTable l (f a)
- genericParseTable :: (Generic a, GParseTable (Rep a)) => ParseTable l a
- genericFromTable :: (Generic a, GParseTable (Rep a)) => Value' l -> Matcher l a
- class GFromArray (f :: Type -> Type) where
  - gFromArray :: StateT [Value' l] (Matcher l) (f a)
- genericFromArray :: (Generic a, GFromArray (Rep a)) => Value' l -> Matcher l a

# Record from table

class GParseTable (f :: Type -> Type) where #

Supports conversion of TOML tables into record values using field selector names as TOML keys.

Methods

gParseTable :: ParseTable l (f a) #

Convert a value and apply the continuation to the result.

#### Instances

Instances details

GParseTable (U1 :: Type -> Type) # | Emits empty table
Instance details Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (U1 a) #
(GParseTable f, GParseTable g) => GParseTable (f :*: g) # | Matches left then right component
Instance details Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l ((f :*: g) a) #
GParseTable f => GParseTable (C1 ('MetaCons sym fix 'True) f) # | Ignores value constructor name - only supports record constructors
Instance details Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (C1 ('MetaCons sym fix 'True) f a) #
GParseTable f => GParseTable (D1 c f) # | Ignores type constructor name
Instance details Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (D1 c f a) #
(Selector s, FromValue a) => GParseTable (S1 s (K1 i (Maybe a) :: Type -> Type)) # | Omits the key from the table on nothing, includes it on just
Instance details Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (S1 s (K1 i (Maybe a) :: Type -> Type) a0) #
(Selector s, FromValue a) => GParseTable (S1 s (K1 i a :: Type -> Type)) # | Uses record selector name as table key
Instance details Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (S1 s (K1 i a :: Type -> Type) a0) #

genericParseTable :: (Generic a, GParseTable (Rep a)) => ParseTable l a #

Match a `Table'` using the field names in a record.

genericFromTable :: (Generic a, GParseTable (Rep a)) => Value' l -> Matcher l a #

Implementation of `fromValue` using `genericParseTable` to derive a match from the record field names of the target type.

# Product type from array

class GFromArray (f :: Type -> Type) where #

Supports conversion of TOML arrays into product-type values.

Methods

gFromArray :: StateT [Value' l] (Matcher l) (f a) #

#### Instances

Instances details

GFromArray (U1 :: Type -> Type) # | Uses no array elements
Instance details Defined in Toml.Schema.Generic.FromValue Methods gFromArray :: StateT [Value' l] (Matcher l) (U1 a) #
(GFromArray f, GFromArray g) => GFromArray (f :*: g) # |
Instance details Defined in Toml.Schema.Generic.FromValue Methods gFromArray :: StateT [Value' l] (Matcher l) ((f :*: g) a) #
FromValue a => GFromArray (K1 i a :: Type -> Type) # |
Instance details Defined in Toml.Schema.Generic.FromValue Methods gFromArray :: StateT [Value' l] (Matcher l) (K1 i a a0) #
GFromArray f => GFromArray (M1 i c f) # |
Instance details Defined in Toml.Schema.Generic.FromValue Methods gFromArray :: StateT [Value' l] (Matcher l) (M1 i c f a) #

genericFromArray :: (Generic a, GFromArray (Rep a)) => Value' l -> Matcher l a #

Match a `Value'` as an array positionally matching field fields of a constructor to the elements of the array.