| Copyright | (c) Eric Mertens 2024 |
|---|---|
| License | ISC |
| Maintainer | emertens@gmail.com |
| Safe Haskell | Safe-Inferred |
| 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
- class GParseTable f
- genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value
- genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table
- class GToArray f
- class GToTable f
DerivingVia
newtype GenericTomlTable a Source #
Constructors
| GenericTomlTable a |
Instances
| (Generic a, GParseTable (Rep a)) => FromValue (GenericTomlTable a) Source # | Instance derived using |
Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlTable a) Source # listFromValue :: Value' l -> Matcher l [GenericTomlTable a] Source # | |
| (Generic a, GToTable (Rep a)) => ToTable (GenericTomlTable a) Source # | Instance derived using |
Defined in Toml.Schema.Generic Methods toTable :: GenericTomlTable a -> Table Source # | |
| (Generic a, GToTable (Rep a)) => ToValue (GenericTomlTable a) Source # | Instance derived from |
Defined in Toml.Schema.Generic Methods toValue :: GenericTomlTable a -> Value Source # toValueList :: [GenericTomlTable a] -> Value Source # | |
newtype GenericTomlArray a Source #
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) Source # | Instance derived using |
Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlArray a) Source # listFromValue :: Value' l -> Matcher l [GenericTomlArray a] Source # | |
| (Generic a, GToArray (Rep a)) => ToValue (GenericTomlArray a) Source # | Instance derived using |
Defined in Toml.Schema.Generic Methods toValue :: GenericTomlArray a -> Value Source # toValueList :: [GenericTomlArray a] -> Value Source # | |
FromValue
genericFromArray :: (Generic a, GFromArray (Rep a)) => Value' l -> Matcher l a Source #
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 Source #
Implementation of fromValue using genericParseTable to derive
a match from the record field names of the target type.
class GFromArray f Source #
Supports conversion of TOML arrays into product-type values.
Minimal complete definition
Instances
| GFromArray (U1 :: Type -> Type) Source # | Uses no array elements |
Defined in Toml.Schema.Generic.FromValue | |
| (GFromArray f, GFromArray g) => GFromArray (f :*: g) Source # | |
Defined in Toml.Schema.Generic.FromValue | |
| FromValue a => GFromArray (K1 i a :: Type -> Type) Source # | |
Defined in Toml.Schema.Generic.FromValue | |
| GFromArray f => GFromArray (M1 i c f) Source # | |
Defined in Toml.Schema.Generic.FromValue | |
class GParseTable f Source #
Supports conversion of TOML tables into record values using field selector names as TOML keys.
Minimal complete definition
Instances
| GParseTable (U1 :: Type -> Type) Source # | Emits empty table |
Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (U1 a) Source # | |
| (GParseTable f, GParseTable g) => GParseTable (f :*: g) Source # | Matches left then right component |
Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l ((f :*: g) a) Source # | |
| GParseTable f => GParseTable (C1 ('MetaCons sym fix 'True) f) Source # | 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) Source # | |
| GParseTable f => GParseTable (D1 c f) Source # | Ignores type constructor name |
Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (D1 c f a) Source # | |
| (Selector s, FromValue a) => GParseTable (S1 s (K1 i (Maybe a) :: Type -> Type)) Source # | 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)) a0) Source # | |
| (Selector s, FromValue a) => GParseTable (S1 s (K1 i a :: Type -> Type)) Source # | Uses record selector name as table key |
Defined in Toml.Schema.Generic.FromValue Methods gParseTable :: ParseTable l (S1 s (K1 i a) a0) Source # | |
ToValue
genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value Source #
Use a record's field names to generate a Value'
genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table Source #
Use a record's field names to generate a Value'
Convert product types to arrays positionally.
Minimal complete definition
Supports conversion of product types with field selector names to TOML values.
Minimal complete definition
Instances
| GToTable (U1 :: Type -> Type) Source # | Emits empty table |
| GToTable (V1 :: Type -> Type) Source # | |
| (GToTable f, GToTable g) => GToTable (f :*: g) Source # | |
| GToTable f => GToTable (C1 c f) Source # | Ignores value constructor names |
| GToTable f => GToTable (D1 c f) Source # | Ignores type constructor names |
| (Selector s, ToValue a) => GToTable (S1 s (K1 i (Maybe a) :: Type -> Type)) Source # | Omits the key from the table on nothing, includes it on just |
| (Selector s, ToValue a) => GToTable (S1 s (K1 i a :: Type -> Type)) Source # | Uses record selector name as table key |