An error is thrown if the list contains duplicates.
>>> input (setFromDistinctList natural) "[1, 1, 3]"
*** Exception: Error: Failed extraction
The expression type-checked successfully but the transformation to the target
type failed with the following error:
One duplicate element in the list: 1
>>> input (setFromDistinctList natural) "[1, 1, 3, 3]"
*** Exception: Error: Failed extraction
The expression type-checked successfully but the transformation to the target
type failed with the following error:
2 duplicates were found in the list, including 1
An error is thrown if the list contains duplicates.
>>> input (hashSetFromDistinctList natural) "[1, 1, 3]"
*** Exception: Error: Failed extraction
The expression type-checked successfully but the transformation to the target
type failed with the following error:
One duplicate element in the list: 1
>>> input (hashSetFromDistinctList natural) "[1, 1, 3, 3]"
*** Exception: Error: Failed extraction
The expression type-checked successfully but the transformation to the target
type failed with the following error:
2 duplicates were found in the list, including 1
The RecordDecoder applicative functor allows you to build a Decoder
from a Dhall record.
For example, let's take the following Haskell data type:
Example1 expression
>>> :{data Project = Project { projectName :: Text , projectDescription :: Text , projectStars :: Natural }:}
And assume that we have the following Dhall record that we would like to
parse as a Project:
{ name =
"dhall-haskell"
, description =
"A configuration language guaranteed to terminate"
, stars =
289
}
Our decoder has type DecoderProject, but we can't build that out of any
smaller decoders, as Decoders cannot be combined (they are only Functors).
However, we can use a RecordDecoder to build a Decoder for Project:
Example1 expression
>>> :{project :: Decoder Projectproject = record ( Project <$> field "name" strictText <*> field "description" strictText <*> field "stars" natural ):}
For example, let's take the following Haskell data type:
Example1 expression
>>> :{data Status = Queued Natural | Result Text | Errored Text:}
And assume that we have the following Dhall union that we would like to
parse as a Status:
< Result : Text
| Queued : Natural
| Errored : Text
>.Result "Finish successfully"
Our decoder has type DecoderStatus, but we can't build that out of any
smaller decoders, as Decoders cannot be combined (they are only Functors).
However, we can use a UnionDecoder to build a Decoder for Status:
genericAuto is the default implementation for auto if you derive
FromDhall. The difference is that you can use genericAuto without
having to explicitly provide a FromDhall instance for a type as long as
the type derives Generic.
Every Decoder must obey the contract that if an expression's type matches
the expected type then the extract function must not fail with a type
error. However, decoding may still fail for other reasons (such as the
decoder for Data.Map.Sets rejecting a Dhall List with duplicate
elements).
This error type is used to indicate an internal error in the implementation
of a Decoder where the expected type matched the Dhall expression, but the
expression supplied to the extraction function did not match the expected
type. If this happens that means that the Decoder itself needs to be
fixed.
Extraction of a value can fail for two reasons, either a type mismatch (which should not happen,
as expressions are type-checked against the expected type before being passed to extract), or
a term-level error, described with a freeform text value.
This is only used by the FromDhall instance for
functions in order to normalize the function input before marshaling the
input into a Dhall expression.
This type is exactly the same as Fix except with a different
FromDhall instance. This intermediate type
simplifies the implementation of the inner loop for the
FromDhall instance for Fix.
DataTextDefined in text-2.1.3 · Data.Text · orphan
This instance preserves data abstraction at the cost of inefficiency.
We omit reflection services for the sake of data abstraction.
This instance was created by copying the updated behavior of
Data.Set.Set and Data.Map.Data.Map.Map. If you
feel a mistake has been made, please feel free to submit
improvements.