| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Yamlet.Value
Description
The values of YAML documents: the content with resolved tags, without the styles, comments and positions of the syntax tree.
A Value has FromYaml and ToYaml
instances, e.g. to read a document whose structure a program does not
know:
>>>decodeText @Value "!point {x: 1, y: 2.5}\n"Right (Tagged "!point" (Mapping [(String "x",Int 1),(String "y",Float (Finite 2.5))]))
An alias becomes a copy of the value that it refers to:
>>>decodeText @Value "base: &b [1, 2]\ncopy: *b\n"Right (Mapping [(String "base",Sequence [Int 1,Int 2]),(String "copy",Sequence [Int 1,Int 2])])
A small input with many aliases can give a large value. To prevent this, the decoder limits the aliases. Each node and each character of a scalar, a tag or an anchor counts as one unit. The aliases can add 100000 units to a document. For a document with more units, they can add as many units as the document has. The documents of a stream share the limit, as if they were one document. A document beyond the limit is an error.
Synopsis
- data Value
- data FloatValue
- = Finite !Scientific
- | NegativeZero
- | Infinity
- | NegativeInfinity
- | NaN
- floatValueToRealFloat :: RealFloat a => FloatValue -> a
- realFloatToFloatValue :: RealFloat a => a -> FloatValue
- describe :: Value -> String
- valueTag :: Value -> Text
- nullTag :: Text
- boolTag :: Text
- intTag :: Text
- floatTag :: Text
- strTag :: Text
- seqTag :: Text
- mapTag :: Text
Values
The value of a node.
Eq and Ord compare the entries of mappings in order, so two mappings
with the same entries in a different order are not equal, unlike in YAML.
Constructors
| Null | |
| Bool !Bool | |
| Int !Integer | |
| Float !FloatValue | |
| String !Text | |
| Sequence ![Value] | |
| Mapping ![(Value, Value)] | The entries of a mapping in the order of the input. The keys are unique. The encoder does not check this for a mapping that a program builds, and a mapping with two equal keys does not read back. Keys are equal as in YAML, e.g. two mappings with the same entries in a different order are equal keys. |
| Tagged !Text !Value | A value with a tag that is not the tag of the core schema for it,
e.g. The encoder writes the tag. Some values read back with a change:
|
Instances
| NFData Value Source # | |||||
Defined in Yamlet.Value | |||||
| Generic Value Source # | |||||
Defined in Yamlet.Value Associated Types
| |||||
| Show Value Source # | |||||
| Eq Value Source # | |||||
| Ord Value Source # | |||||
| FromYaml Value Source # | The value of the node, with the tags resolved and the aliases replaced. | ||||
| ToYaml Value Source # | |||||
| type Rep Value Source # | |||||
Defined in Yamlet.Value type Rep Value = D1 ('MetaData "Value" "Yamlet.Value" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) (((C1 ('MetaCons "Null" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Bool" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :+: (C1 ('MetaCons "Int" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "Float" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FloatValue)))) :+: ((C1 ('MetaCons "String" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "Sequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [Value]))) :+: (C1 ('MetaCons "Mapping" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [(Value, Value)])) :+: C1 ('MetaCons "Tagged" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Value))))) | |||||
data FloatValue Source #
The value of a floating-point number. A finite value is exact, e.g. 0.1
is exactly one tenth.
Arithmetic on a Scientific with a huge exponent, e.g.
1e1000000000, can use all memory. Convert a value from an untrusted input
with floatValueToRealFloat or with the bounded conversions of
Data.Scientific.
Constructors
| Finite !Scientific | A finite value other than negative zero. The encoder writes a value whose exponent in scientific notation is
beyond the range from -1000 to 1000, e.g. |
| NegativeZero | Negative zero, e.g. |
| Infinity | |
| NegativeInfinity | |
| NaN |
Instances
| NFData FloatValue Source # | |||||
Defined in Yamlet.Value Methods rnf :: FloatValue -> () | |||||
| Generic FloatValue Source # | |||||
Defined in Yamlet.Value Associated Types
| |||||
| Show FloatValue Source # | |||||
Defined in Yamlet.Value Methods showsPrec :: Int -> FloatValue -> ShowS show :: FloatValue -> String showList :: [FloatValue] -> ShowS | |||||
| Eq FloatValue Source # | |||||
Defined in Yamlet.Value | |||||
| Ord FloatValue Source # | |||||
Defined in Yamlet.Value Methods compare :: FloatValue -> FloatValue -> Ordering (<) :: FloatValue -> FloatValue -> Bool (<=) :: FloatValue -> FloatValue -> Bool (>) :: FloatValue -> FloatValue -> Bool (>=) :: FloatValue -> FloatValue -> Bool max :: FloatValue -> FloatValue -> FloatValue min :: FloatValue -> FloatValue -> FloatValue | |||||
| type Rep FloatValue Source # | |||||
Defined in Yamlet.Value type Rep FloatValue = D1 ('MetaData "FloatValue" "Yamlet.Value" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) ((C1 ('MetaCons "Finite" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Scientific)) :+: C1 ('MetaCons "NegativeZero" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Infinity" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "NegativeInfinity" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NaN" 'PrefixI 'False) (U1 :: Type -> Type)))) | |||||
floatValueToRealFloat :: RealFloat a => FloatValue -> a Source #
The nearest value of a floating-point type, e.g. Double, infinite if
the value is out of its range. The decimal converts to the type directly,
so it is rounded once, e.g. a Float does not go by way of a Double.
>>>map (floatValueToRealFloat @Double) [Finite 0.1, Finite 1e400, NegativeZero][0.1,Infinity,-0.0]
realFloatToFloatValue :: RealFloat a => a -> FloatValue Source #
The value of a floating-point number, e.g. a Double. A finite number
becomes the shortest decimal that reads back as the same number, e.g.
0.1.
>>>map (realFloatToFloatValue @Double) [0.1, -0, 1 / 0][Finite 0.1,NegativeZero,Infinity]
describe :: Value -> String Source #
The kind of a value in plain words, for error messages, e.g. "a list".
The tag of Tagged does not change it.
>>>describe (Tagged "!point" (Mapping []))"a mapping"