tomland-1.3.3.3: Bidirectional TOML serialization

Copyright | (c) 2018-2022 Kowainik
License | MPL-2.0
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | None
Language | Haskell2010

Toml.Type.Value

Contents

- Type of value
- Value
- Type checking

Description

GADT value for TOML.

Since: 0.0.0

Synopsis

- data TValue
  - = TBool
  - | TInteger
  - | TDouble
  - | TText
  - | TZoned
  - | TLocal
  - | TDay
  - | THours
  - | TArray
- showType :: TValue -> String
- data Value (t :: TValue) where
  - Bool :: Bool -> Value 'TBool
  - Integer :: Integer -> Value 'TInteger
  - Double :: Double -> Value 'TDouble
  - Text :: Text -> Value 'TText
  - Zoned :: ZonedTime -> Value 'TZoned
  - Local :: LocalTime -> Value 'TLocal
  - Day :: Day -> Value 'TDay
  - Hours :: TimeOfDay -> Value 'THours
  - Array :: forall (t1 :: TValue). [Value t1] -> Value 'TArray
- eqValueList :: forall (a :: TValue) (b :: TValue). [Value a] -> [Value b] -> Bool
- valueType :: forall (t :: TValue). Value t -> TValue
- data TypeMismatchError = TypeMismatchError {
  - typeExpected :: !TValue
  - typeActual :: !TValue
  }
- sameValue :: forall (a :: TValue) (b :: TValue). Value a -> Value b -> Either TypeMismatchError (a :~: b)

# Type of value

data TValue #

Needed for GADT parameterization

Since: 0.0.0

Constructors

TBool |
TInteger |
TDouble |
TText |
TZoned |
TLocal |
TDay |
THours |
TArray |

#### Instances

Instances details

NFData TValue # |
Instance details Defined in Toml.Type.Value Methods rnf :: TValue -> () #
Generic TValue # |

Instance details

Defined in Toml.Type.Value

Associated Types

type Rep TValue |

Instance details

Defined in Toml.Type.Value

type Rep TValue = D1 ('MetaData "TValue" "Toml.Type.Value" "tomland-1.3.3.3-EUmut0o3bp2HnXO9U1VNsY" 'False) (((C1 ('MetaCons "TBool" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TInteger" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TDouble" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TText" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "TZoned" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TLocal" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TDay" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "THours" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TArray" 'PrefixI 'False) (U1 :: Type -> Type)))))

Methods

from :: TValue -> Rep TValue x #

to :: Rep TValue x -> TValue #

Read TValue # |
Instance details Defined in Toml.Type.Value Methods readsPrec :: Int -> ReadS TValue # readList :: ReadS [TValue] # readPrec :: ReadPrec TValue # readListPrec :: ReadPrec [TValue] #
Show TValue # |
Instance details Defined in Toml.Type.Value Methods showsPrec :: Int -> TValue -> ShowS # show :: TValue -> String # showList :: [TValue] -> ShowS #
Eq TValue # |
Instance details Defined in Toml.Type.Value Methods (==) :: TValue -> TValue -> Bool # (/=) :: TValue -> TValue -> Bool #
type Rep TValue # |

Instance details

Defined in Toml.Type.Value

type Rep TValue = D1 ('MetaData "TValue" "Toml.Type.Value" "tomland-1.3.3.3-EUmut0o3bp2HnXO9U1VNsY" 'False) (((C1 ('MetaCons "TBool" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TInteger" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TDouble" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TText" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "TZoned" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TLocal" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TDay" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "THours" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TArray" 'PrefixI 'False) (U1 :: Type -> Type)))))

showType :: TValue -> String #

Convert `TValue` constructors to `String` without `T` prefix.

Since: 0.0.0

# Value

data Value (t :: TValue) where #

Value in `key = value` pair.

Since: 0.0.0

Constructors

Bool :: Bool -> Value 'TBool

Boolean value:

    bool1 = true
    bool2 = false

Integer :: Integer -> Value 'TInteger

Integer value:

    int1 = +99
    int2 = 42
    int3 = 0
    int4 = -17
    int5 = 5_349_221
    hex1 = 0xDEADBEEF  # hexadecimal
    oct2 = 0o755  # octal, useful for Unix file permissions
    bin1 = 0b11010110  # binary

Double :: Double -> Value 'TDouble

Floating point number:

    # fractional
    flt1 = +1.0
    flt2 = 3.1415
    flt3 = -0.01

    # exponent
    flt4 = 5e+22
    flt5 = 1e6
    flt6 = -2E-2

    # both
    flt7 = 6.626e-34

    # infinity
    sf1 = inf  # positive infinity
    sf2 = +inf # positive infinity
    sf3 = -inf # negative infinity

    # not a number
    sf4 = nan  # actual sNaN/qNaN encoding is implementation specific
    sf5 = +nan # same as `nan`
    sf6 = -nan # same as `nan`

Text :: Text -> Value 'TText

String value:

    # basic string
    name = "Orange"
    physical.color = "orange"
    physical.shape = "round"

    # multiline basic string
    str1 = """
    Roses are red
    Violets are blue"""

    # literal string: What you see is what you get.
    winpath  = 'C:Usersnodejstemplates'
    winpath2 = '\ServerXadmin$system32'
    quoted   = 'Tom "Dubs" Preston-Werner'
    regex    = 'ic*s*'

Zoned :: ZonedTime -> Value 'TZoned

Offset date-time:

    odt1 = 1979-05-27T07:32:00Z
    odt2 = 1979-05-27T00:32:00-07:00
    odt3 = 1979-05-27T00:32:00.999999-07:00

Local :: LocalTime -> Value 'TLocal

Local date-time (without offset):

    ldt1 = 1979-05-27T07:32:00
    ldt2 = 1979-05-27T00:32:00.999999

Day :: Day -> Value 'TDay

Local date (only day):

    ld1 = 1979-05-27

Hours :: TimeOfDay -> Value 'THours

Local time (time of the day):

    lt1 = 07:32:00
    lt2 = 00:32:00.999999

Array :: forall (t1 :: TValue). [Value t1] -> Value 'TArray

Array of values. According to TOML specification all values in array should have the same type. This is guaranteed statically with this type.

    arr1 = [ 1, 2, 3 ]
    arr2 = [ "red", "yellow", "green" ]
    arr3 = [ [ 1, 2 ], [3, 4, 5] ]
    arr4 = [ "all", 'strings', """are the same""", '''type''']
    arr5 = [ [ 1, 2 ], ["a", "b", "c"] ]

    arr6 = [ 1, 2.0 ] # INVALID

#### Instances

Instances details

NFData (Value t) # |
Instance details Defined in Toml.Type.Value Methods rnf :: Value t -> () #
t ~ 'TText => IsString (Value t) # |
Instance details Defined in Toml.Type.Value Methods fromString :: String -> Value t #
t ~ 'TInteger => Num (Value t) # |
Instance details Defined in Toml.Type.Value Methods (+) :: Value t -> Value t -> Value t # (-) :: Value t -> Value t -> Value t # (*) :: Value t -> Value t -> Value t # negate :: Value t -> Value t # abs :: Value t -> Value t # signum :: Value t -> Value t # fromInteger :: Integer -> Value t #
Show (Value t) # | Since: 0.0.0
Instance details Defined in Toml.Type.Value Methods showsPrec :: Int -> Value t -> ShowS # show :: Value t -> String # showList :: [Value t] -> ShowS #
Eq (Value t) # |
Instance details Defined in Toml.Type.Value Methods (==) :: Value t -> Value t -> Bool # (/=) :: Value t -> Value t -> Bool #

eqValueList :: forall (a :: TValue) (b :: TValue). [Value a] -> [Value b] -> Bool #

Compare list of `Value` of possibly different types.

Since: 0.0.0

valueType :: forall (t :: TValue). Value t -> TValue #

Reifies type of `Value` into `TValue`. Unfortunately, there's no way to guarantee that `valueType` will return `t` for object with type `Value 't`.

Since: 0.0.0

# Type checking

data TypeMismatchError #

Data type that holds expected vs. actual type.

Since: 0.1.0

Constructors

TypeMismatchError |

Fields

- typeExpected :: !TValue
- typeActual :: !TValue

#### Instances

Instances details

Show TypeMismatchError # | Since: 0.1.0
Instance details Defined in Toml.Type.Value Methods showsPrec :: Int -> TypeMismatchError -> ShowS # show :: TypeMismatchError -> String # showList :: [TypeMismatchError] -> ShowS #
Eq TypeMismatchError # |
Instance details Defined in Toml.Type.Value Methods (==) :: TypeMismatchError -> TypeMismatchError -> Bool # (/=) :: TypeMismatchError -> TypeMismatchError -> Bool #

sameValue :: forall (a :: TValue) (b :: TValue). Value a -> Value b -> Either TypeMismatchError (a :~: b) #

Checks whether two values are the same. This function is used for type checking where first argument is expected type and second argument is actual type.

Since: 0.0.0