| Copyright | (c) Eric Mertens 2024 |
|---|---|
| License | ISC |
| Maintainer | emertens@gmail.com |
| Safe Haskell | None |
| Language | Haskell2010 |
Toml.Schema.Generic
Contents
Description
This module makes it possible to easily derive the TOML classes
using the DerivingVia extension.
For example:
data Physical = Physical {
color :: String,
shape :: String
}
deriving (Eq, Show, Generic)
deriving (ToTable, ToValue, FromValue) via GenericTomlTable Physical
These derived instances would allow you to match TOML
{color="red", shape="round"} to value Physical "red" "round".
data Coord = Coord Int Int
deriving (Eq, Show, Generic)
deriving (ToValue, FromValue) via GenericTomlArray Physical
These derived instances would allow you to match TOML [1,2] to value Coord 1 2.
Synopsis
- newtype GenericTomlTable a = GenericTomlTable a
- newtype GenericTomlArray a = GenericTomlArray a
- genericFromArray :: (Generic a, GFromArray (Rep a)) => Value' l -> Matcher l a
- genericFromTable :: (Generic a, GParseTable (Rep a)) => Value' l -> Matcher l a
- class GFromArray (f :: Type -> Type)
- class GParseTable (f :: Type -> Type)
- genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value
- genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table
- class GToArray (f :: Type -> Type)
- class GToTable (f :: Type -> Type)
DerivingVia
newtype GenericTomlTable a #
Constructors
| GenericTomlTable a |
Instances
| (Generic a, GParseTable (Rep a)) => FromValue (GenericTomlTable a) # | Instance derived using |
Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlTable a) # listFromValue :: Value' l -> Matcher l [GenericTomlTable a] # | |
| (Generic a, GToTable (Rep a)) => ToTable (GenericTomlTable a) # | Instance derived using |
Defined in Toml.Schema.Generic Methods toTable :: GenericTomlTable a -> Table # | |
| (Generic a, GToTable (Rep a)) => ToValue (GenericTomlTable a) # | Instance derived from |
Defined in Toml.Schema.Generic | |
newtype GenericTomlArray a #
Helper type to use GHC's DerivingVia extension to derive
ToValue, ToTable, FromValue for any product type.
Constructors
| GenericTomlArray a |
Instances
| (Generic a, GFromArray (Rep a)) => FromValue (GenericTomlArray a) # | Instance derived using |
Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlArray a) # listFromValue :: Value' l -> Matcher l [GenericTomlArray a] # | |
| (Generic a, GToArray (Rep a)) => ToValue (GenericTomlArray a) # | Instance derived using |
Defined in Toml.Schema.Generic | |
FromValue
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.
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.
class GFromArray (f :: Type -> Type) #
Supports conversion of TOML arrays into product-type values.
Minimal complete definition
Instances
| GFromArray (U1 :: Type -> Type) # | Uses no array elements |
Defined in Toml.Schema.Generic.FromValue | |
| (GFromArray f, GFromArray g) => GFromArray (f :*: g) # | |
Defined in Toml.Schema.Generic.FromValue | |
| FromValue a => GFromArray (K1 i a :: Type -> Type) # | |
Defined in Toml.Schema.Generic.FromValue | |
| GFromArray f => GFromArray (M1 i c f) # | |
Defined in Toml.Schema.Generic.FromValue | |
class GParseTable (f :: Type -> Type) #
Supports conversion of TOML tables into record values using field selector names as TOML keys.
Minimal complete definition
Instances
| GParseTable (U1 :: Type -> Type) # | Emits empty table |
Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (U1 a) # | |
| (GParseTable f, GParseTable g) => GParseTable (f :*: g) # | Matches left then right component |
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 |
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 |
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 |
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 |
Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (S1 s (K1 i a :: Type -> Type) a0) # | |
ToValue
genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value #
Use a record's field names to generate a Table
genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table #
Use a record's field names to generate a Table
class GToArray (f :: Type -> Type) #
Convert product types to arrays positionally.
Minimal complete definition
class GToTable (f :: Type -> Type) #
Supports conversion of product types with field selector names to TOML values.
Minimal complete definition
Instances
| GToTable (U1 :: Type -> Type) # | Emits empty table |
| GToTable (V1 :: Type -> Type) # | |
| (GToTable f, GToTable g) => GToTable (f :*: g) # | |
| GToTable f => GToTable (C1 c f) # | Ignores value constructor names |
| GToTable f => GToTable (D1 c f) # | Ignores type constructor names |
| (Selector s, ToValue a) => GToTable (S1 s (K1 i (Maybe a) :: Type -> Type)) # | Omits the key from the table on nothing, includes it on just |
| (Selector s, ToValue a) => GToTable (S1 s (K1 i a :: Type -> Type)) # | Uses record selector name as table key |