-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Convert between Dhall and JSON or YAML
--   
--   Use this package if you want to convert between Dhall expressions and
--   JSON or YAML. You can use this package as a library or an executable:
--   
--   <ul>
--   <li>See the <a>Dhall.JSON</a> or <a>Dhall.JSONToDhall</a> modules if
--   you want to use this package as a library</li>
--   <li>Use the <tt>dhall-to-json</tt>, <tt>dhall-to-yaml</tt>, or
--   <tt>json-to-dhall</tt> programs from this package if you want an
--   executable</li>
--   </ul>
--   
--   The <a>Dhall.JSON</a> and <a>Dhall.JSONToDhall</a> modules also
--   contains instructions for how to use this package
@package dhall-json
@version 1.7.12


-- | This library only exports a single <a>dhallToJSON</a> function for
--   translating a Dhall syntax tree to a JSON syntax tree (i.e. a
--   <a>Value</a>) for the <tt>aeson</tt> library
--   
--   NOTE: The <tt>yaml</tt> library uses the same <a>Value</a> type to
--   represent YAML files, so you can use this to convert Dhall expressions
--   to YAML, too
--   
--   See the <tt>dhall</tt> package if you would like to transform Dhall
--   source code into a Dhall syntax tree. Similarly, see the
--   <tt>aeson</tt> package if you would like to translate a JSON syntax
--   tree into JSON.
--   
--   This package also provides <tt>dhall-to-json</tt> and
--   <tt>dhall-to-yaml</tt> executables which you can use to compile Dhall
--   source code directly to JSON or YAML for your convenience
--   
--   Not all Dhall expressions can be converted to JSON since JSON is not a
--   programming language. The only things you can convert are:
--   
--   <ul>
--   <li><tt>Bool</tt>s</li>
--   <li><tt>Natural</tt>s</li>
--   <li><tt>Integer</tt>s</li>
--   <li><tt>Double</tt>s</li>
--   <li><tt>Text</tt> values</li>
--   <li><tt>List</tt>s</li>
--   <li><tt>Optional</tt> values</li>
--   <li>unions</li>
--   <li>records</li>
--   </ul>
--   
--   Dhall <tt>Bool</tt>s translate to JSON bools:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; 'True'
--   true
--   $ dhall-to-json &lt;&lt;&lt; 'False'
--   false
--   </pre>
--   
--   Dhall numbers translate to JSON numbers:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; '+2'
--   2
--   $ dhall-to-json &lt;&lt;&lt; '2'
--   2
--   $ dhall-to-json &lt;&lt;&lt; '2.3'
--   2.3
--   </pre>
--   
--   Dhall <tt>Text</tt> translates to JSON text:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; '"ABC"'
--   "ABC"
--   </pre>
--   
--   Dhall <tt>List</tt>s translate to JSON lists:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; '[1, 2, 3] : List Natural'
--   [
--     1,
--     2,
--     3
--   ]
--   </pre>
--   
--   Dhall <tt>Optional</tt> values translate to <tt>null</tt> if absent
--   and the unwrapped value otherwise:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; 'None Natural'
--   null
--   $ dhall-to-json &lt;&lt;&lt; 'Some 1'
--   1
--   </pre>
--   
--   Dhall records translate to JSON records:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; '{ foo = 1, bar = True }'
--   {
--     "bar": true,
--     "foo": 1
--   }
--   </pre>
--   
--   Dhall unions translate to the wrapped value:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; "&lt; Left : Natural | Right : Natural&gt;.Left 2"
--   2
--   $ cat config
--   let MyType =
--         &lt; Person : { age : Natural, name : Text } | Place : { location : Text } &gt;
--   
--   in  [ MyType.Person { age = 47, name = "John" }
--       , MyType.Place { location = "North Pole" }
--       , MyType.Place { location = "Sahara Desert" }
--       , MyType.Person { age = 35, name = "Alice" }
--       ]
--   $ dhall-to-json &lt;&lt;&lt; "./config"
--   [
--     {
--       "age": 47,
--       "name": "John"
--     },
--     {
--       "location": "North Pole"
--     },
--     {
--       "location": "Sahara Desert"
--     },
--     {
--       "age": 35,
--       "name": "Alice"
--     }
--   ]
--   </pre>
--   
--   You can preserve the name of the alternative if you wrap the value in
--   a record with three fields:
--   
--   <ul>
--   <li><tt>contents</tt>: The union literal that you want to preserve the
--   tag of</li>
--   <li><tt>field</tt>: the name of the field that will store the name of
--   the alternative</li>
--   <li><tt>nesting</tt>: A value of type <tt>&lt; Inline | Nested : Text
--   &gt;</tt>.</li>
--   </ul>
--   
--   If <tt>nesting</tt> is set to <tt>Inline</tt> and the union literal
--   stored in <tt>contents</tt> contains a record then the name of the
--   alternative is stored inline within the same record. For example, this
--   code:
--   
--   <pre>
--   let Example = &lt; Left : { foo : Natural } | Right : { bar : Bool } &gt;
--   
--   let Nesting = &lt; Inline | Nested : Text &gt;
--   
--   in  { field    = "name"
--       , nesting  = Nesting.Inline
--       , contents = Example.Left { foo = 2 }
--       }
--   </pre>
--   
--   ... produces this JSON:
--   
--   <pre>
--   {
--     "foo": 2,
--     "name": "Left"
--   }
--   </pre>
--   
--   If <tt>nesting</tt> is set to <tt>Nested nestedField</tt> then the
--   union is stored underneath a field named <tt>nestedField</tt>. For
--   example, this code:
--   
--   <pre>
--   let Example = &lt; Left : { foo : Natural } | Right : { bar : Bool } &gt;
--   
--   let Nesting = &lt; Inline | Nested : Text &gt;
--   
--   in  { field    = "name"
--       , nesting  = Nesting.Nested "value"
--       , contents = Example.Left { foo = 2 }
--       }
--   </pre>
--   
--   ... produces this JSON:
--   
--   <pre>
--   {
--     "name": "Left",
--     "value": {
--       "foo": 2
--     }
--   }
--   </pre>
--   
--   You can also translate Dhall expressions encoding weakly-typed JSON
--   (see: <a>https://prelude.dhall-lang.org/JSON/Type</a>):
--   
--   <pre>
--   $ cat ./example.dhall
--   let JSON = https://prelude.dhall-lang.org/JSON/package.dhall
--   
--   in  JSON.object
--       [ { mapKey = "foo", mapValue = JSON.null }
--       , { mapKey =
--             "bar"
--         , mapValue =
--             JSON.array [ JSON.number 1.0, JSON.bool True ]
--         }
--       ]
--   </pre>
--   
--   By default, the fields that are evaluated to <tt>null</tt> will be
--   removed, but here we're preserving them with the
--   <tt>--preserveNull</tt> flag.
--   
--   <pre>
--   $ dhall-to-json --preserveNull &lt;&lt;&lt; './example.dhall'
--   {
--     "bar": [
--       1,
--       true
--     ],
--     "foo": null
--   }
--   </pre>
--   
--   Also, all Dhall expressions are normalized before translation to JSON:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; "True == False"
--   false
--   </pre>
module Dhall.JSON

-- | Convert a Dhall expression to the equivalent JSON expression
--   
--   <pre>
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; :set -XOverloadedLists
--   
--   &gt;&gt;&gt; import Core
--   
--   &gt;&gt;&gt; dhallToJSON (RecordLit [("foo", IntegerLit 1), ("bar", TextLit "ABC")])
--   Right (Object (fromList [("foo",Number 1.0),("bar",String "ABC")]))
--   
--   &gt;&gt;&gt; fmap Aeson.encode it
--   Right "{\"foo\":1,\"bar\":\"ABC\"}"
--   </pre>
dhallToJSON :: Expr s Void -> Either CompileError Value

-- | Omit record fields that are <tt>null</tt>
omitNull :: Value -> Value

-- | Omit record fields that are <tt>null</tt>, arrays and records whose
--   transitive fields are all null
omitEmpty :: Value -> Value

-- | Combines parsers for command-line options related to preserving &amp;
--   omitting null fields.
parsePreservationAndOmission :: Parser (Value -> Value)

-- | Specify whether or not to convert association lists of type <tt>List {
--   mapKey: Text, mapValue : v }</tt> to records
data Conversion
NoConversion :: Conversion
Conversion :: Text -> Text -> Conversion
[mapKey] :: Conversion -> Text
[mapValue] :: Conversion -> Text
defaultConversion :: Conversion

-- | Convert association lists to homogeneous maps
--   
--   This converts an association list of the form:
--   
--   <pre>
--   [ { mapKey = k0, mapValue = v0 }, { mapKey = k1, mapValue = v1 } ]
--   </pre>
--   
--   ... to a record of the form:
--   
--   <pre>
--   { k0 = v0, k1 = v1 }
--   </pre>
convertToHomogeneousMaps :: Conversion -> Expr s Void -> Expr s Void

-- | Parser for command-line options related to homogeneous map support
parseConversion :: Parser Conversion

-- | This option specifies how to encode
--   <tt>NaN</tt>/<tt>Infinity</tt>/<tt>-Infinity</tt>
data SpecialDoubleMode

-- | YAML natively supports
--   <tt>NaN</tt>/<tt>Infinity</tt>/<tt>-Infinity</tt>
UseYAMLEncoding :: SpecialDoubleMode

-- | Forbid <tt>NaN</tt>/<tt>Infinity</tt>/<tt>-Infinity</tt> because JSON
--   doesn't support them
ForbidWithinJSON :: SpecialDoubleMode

-- | Encode <tt>NaN</tt>/<tt>Infinity</tt>/<tt>-Infinity</tt> as
--   <tt>null</tt>/<tt>1.7976931348623157e308</tt>/<tt>-1.7976931348623157e308</tt>,
--   respectively
ApproximateWithinJSON :: SpecialDoubleMode

-- | Pre-process an expression containing
--   <tt>NaN</tt>/<tt>Infinity</tt>/<tt>-Infinity</tt>, handling them as
--   specified according to the <a>SpecialDoubleMode</a>
handleSpecialDoubles :: SpecialDoubleMode -> Expr s Void -> Either CompileError (Expr s Void)

-- | Convert a piece of Text carrying a Dhall inscription to an equivalent
--   JSON Value
--   
--   <pre>
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; import Core
--   
--   &gt;&gt;&gt; Dhall.JSON.codeToValue defaultConversion ForbidWithinJSON Nothing "{ a = 1 }"
--   
--   &gt;&gt;&gt; Object (fromList [("a",Number 1.0)])
--   </pre>
codeToValue :: Conversion -> SpecialDoubleMode -> Maybe FilePath -> Text -> IO Value

-- | This is like <a>codeToValue</a>, except also returning a <a>Header</a>
--   that is a valid YAML comment derived from the original Dhall code's
--   <a>Header</a>
codeToHeaderAndValue :: Conversion -> SpecialDoubleMode -> Maybe FilePath -> Text -> IO (Header, Value)

-- | This is the exception type for errors that might arise when
--   translating Dhall to JSON
--   
--   Because the majority of Dhall language features do not translate to
--   JSON this just returns the expression that failed
data CompileError
Unsupported :: Expr Void Void -> CompileError
SpecialDouble :: Double -> CompileError
BareNone :: CompileError
InvalidInlineContents :: Expr Void Void -> Expr Void Void -> CompileError
instance GHC.Show.Show Dhall.JSON.CompileError
instance GHC.Exception.Type.Exception Dhall.JSON.CompileError


-- | Convert Dhall to YAML via JSON
--   
--   Since JSON is only a subset of YAML, the functionality offered here is
--   more limited than what the <tt>dhall-yaml</tt> package can offer.
module Dhall.JSON.Yaml
data Options
Options :: Bool -> (Value -> Value) -> Bool -> Bool -> Conversion -> Maybe FilePath -> Maybe FilePath -> Bool -> Bool -> Options
[explain] :: Options -> Bool
[omission] :: Options -> Value -> Value
[documents] :: Options -> Bool
[quoted] :: Options -> Bool
[conversion] :: Options -> Conversion
[file] :: Options -> Maybe FilePath
[output] :: Options -> Maybe FilePath
[noEdit] :: Options -> Bool
[preserveHeader] :: Options -> Bool
parseDocuments :: Parser Bool
parseQuoted :: Parser Bool
defaultOptions :: Options

-- | Convert a piece of Text carrying a Dhall inscription to an equivalent
--   YAML ByteString
dhallToYaml :: Options -> Maybe FilePath -> Text -> IO ByteString

-- | Transform json representation into yaml
jsonToYaml :: Value -> Bool -> Bool -> ByteString

-- | The notice added to the top of a generated file when enabling the
--   <tt>--generated-comment</tt>
generatedCodeNotice :: ByteString

module Dhall.DhallToYaml.Main
main :: Version -> (Options -> Maybe FilePath -> Text -> IO ByteString) -> IO ()


-- | Convert JSON data to Dhall in one of two ways:
--   
--   <ul>
--   <li>By default, the conversion will make a best-effort at inferring
--   the corresponding Dhall type</li>
--   <li>Optionally, you can specify an expected Dhall type necessary to
--   make the translation unambiguous.</li>
--   </ul>
--   
--   Either way, if you supply the generated Dhall result to
--   <tt>dhall-to-json</tt> you should get back the original JSON.
--   
--   Only a subset of Dhall types are supported when converting from JSON:
--   
--   <ul>
--   <li><pre>Bool</pre></li>
--   <li><pre>Natural</pre></li>
--   <li><pre>Integer</pre></li>
--   <li><pre>Double</pre></li>
--   <li><pre>Text</pre></li>
--   <li><pre>List</pre></li>
--   <li><pre>Optional</pre></li>
--   <li>unions</li>
--   <li>records</li>
--   <li><pre>Prelude.Type.Map</pre></li>
--   <li><tt>Prelude.Type.JSON</tt> - You can always convert JSON data to
--   this type as a last resort if you don't know the schema in
--   advance.</li>
--   </ul>
--   
--   You can use this code as a library (this module) or as an executable
--   named <tt>json-to-dhall</tt>, which is used in the examples below.
--   
--   By default the <tt>json-to-dhall</tt> executable attempts to infer the
--   appropriate Dhall type from the JSON data, like this:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; 1
--   1
--   </pre>
--   
--   ... but you can also provide an explicit schema on the command line if
--   you prefer a slightly different Dhall type which still represents the
--   same JSON value:
--   
--   <pre>
--   $ json-to-dhall Integer &lt;&lt;&lt; 1
--   +1
--   </pre>
--   
--   You can also get the best of both worlds by using the <tt>type</tt>
--   subcommand to infer the schema:
--   
--   <pre>
--   $ json-to-dhall type &lt;&lt;&lt; '[ "up", "down" ]' | tee schema.dhall
--   List Text
--   </pre>
--   
--   ... and then edit the <tt>./schema.dhall</tt> file to better match the
--   type you intended, such as:
--   
--   <pre>
--   $ $EDITOR schema.dhall
--   $ cat ./schema.dhall
--   List &lt; up | down &gt;
--   </pre>
--   
--   ... and then use the edited schema for subsequent conversions:
--   
--   <pre>
--   $ json-to-dhall ./schema.dhall &lt;&lt;&lt; '[ "up", "down" ]'
--   [ &lt; down | up &gt;.up, &lt; down | up &gt;.down ]
--   </pre>
--   
--   <h2>Primitive types</h2>
--   
--   JSON <tt>Bool</tt>s translate to Dhall bools:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; 'true'
--   True
--   $ json-to-dhall &lt;&lt;&lt; 'false'
--   False
--   </pre>
--   
--   JSON numbers translate to Dhall numbers:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; 2
--   2
--   $ json-to-dhall &lt;&lt;&lt; -2
--   -2
--   $ json-to-dhall &lt;&lt;&lt; -2.1
--   -2.1
--   $ json-to-dhall Natural &lt;&lt;&lt; 2
--   2
--   $ json-to-dhall Integer &lt;&lt;&lt; 2
--   +2
--   $ json-to-dhall Double &lt;&lt;&lt; 2
--   2.0
--   </pre>
--   
--   JSON text corresponds to Dhall <tt>Text</tt> by default:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; '"foo bar"'
--   "foo bar"
--   </pre>
--   
--   ... but you can also decode text into a more structured enum, too, if
--   you provide an explicit schema:
--   
--   <pre>
--   $ json-to-dhall '&lt; A | B &gt;' &lt;&lt;&lt; '"A"'
--   &lt; A | B &gt;.A
--   </pre>
--   
--   <h2>Lists and records</h2>
--   
--   Dhall <tt>List</tt>s correspond to JSON lists:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; '[ 1, 2, 3 ]'
--   [ 1, 2, 3 ]
--   </pre>
--   
--   You can even decode an empty JSON list to Dhall:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; '[]'
--   [] : List &lt;&gt;
--   </pre>
--   
--   ... which will infer the empty <tt>&lt;&gt;</tt> type if there are no
--   other constraints on the type. If you provide an explicit type
--   annotation then the conversion will use that instead:
--   
--   <pre>
--   $ json-to-dhall 'List Natural' &lt;&lt;&lt; '[]'
--   [] : List Natural
--   </pre>
--   
--   Dhall records correspond to JSON records:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; '{ "foo": [ 1, 2, 3 ] }'
--   { foo = [ 1, 2, 3 ] }
--   </pre>
--   
--   If you specify a schema with additional <tt>Optional</tt> fields then
--   they will be <tt>None</tt> if absent:
--   
--   <pre>
--   $ json-to-dhall '{ foo : List Natural, bar : Optional Bool }' &lt;&lt;&lt; '{ "foo": [ 1, 2, 3 ] }'
--   { bar = None Bool, foo = [ 1, 2, 3 ] }
--   </pre>
--   
--   ... and <tt>Some</tt> if present:
--   
--   <pre>
--   $ json-to-dhall '{ foo : List Natural, bar : Optional Bool }' &lt;&lt;&lt; '{ "foo": [ 1, 2, 3 ], "bar": true }'
--   { bar = Some True, foo = [ 1, 2, 3 ] }
--   </pre>
--   
--   If you specify a schema with too few fields, then the behavior is
--   configurable. By default, the conversion will reject extra fields:
--   
--   <pre>
--   $ json-to-dhall '{ foo : List Natural }' &lt;&lt;&lt; '{ "foo": [ 1, 2, 3 ], "bar": true }'
--   
--   Error: Key(s) bar present in the JSON object but not in the expected Dhall record type. This is not allowed unless you enable the --records-loose flag:
--   
--   Expected Dhall type:
--   { foo : List Natural }
--   
--   JSON:
--   {
--       "foo": [
--           1,
--           2,
--           3
--       ],
--       "bar": true
--   }
--   </pre>
--   
--   ... as the error message suggests, extra fields are ignored if you
--   enable the <tt>--records-loose</tt> flag.
--   
--   <pre>
--   $ json-to-dhall --records-loose '{ foo : List Natural }' &lt;&lt;&lt; '{ "foo": [ 1, 2, 3 ], "bar": true }'
--   { foo = [ 1, 2, 3 ] }
--   </pre>
--   
--   You can convert JSON key-value arrays to Dhall records, but only if
--   you supply an explicit Dhall type:
--   
--   <pre>
--   $ json-to-dhall '{ a : Natural, b : Text }' &lt;&lt;&lt; '[ { "key": "a", "value": 1 }, { "key": "b", "value": "asdf" } ]'
--   { a = 1, b = "asdf" }
--   </pre>
--   
--   You can also disable this behavior using the
--   <tt>--no-keyval-arrays</tt>:
--   
--   <pre>
--   $ json-to-dhall --no-keyval-arrays '{ a : Natural, b : Text }' &lt;&lt;&lt; '[ { "key": "a", "value": 1 }, { "key": "b", "value": "asdf" } ]'
--   Error: JSON (key-value) arrays cannot be converted to Dhall records under --no-keyval-arrays flag:
--   </pre>
--   
--   You can also convert JSON records to Dhall <tt>Map</tt>s, but only if
--   you supply an explicit schema:
--   
--   <pre>
--   $ json-to-dhall 'List { mapKey : Text, mapValue : Text }' &lt;&lt;&lt; '{ "foo": "bar" }'
--   toMap { foo = "bar" }
--   </pre>
--   
--   The map keys can even be union types instead of <a>Schema</a>:
--   
--   <pre>
--   $ json-to-dhall 'List { mapKey : &lt; A | B &gt;, mapValue : Natural }' &lt;&lt;&lt; '{ "A": 1, "B": 2 }'
--   [ { mapKey = &lt; A | B &gt;.A, mapValue = 1 }, { mapKey = &lt; A | B &gt;.B, mapValue = 2 } ]
--   </pre>
--   
--   You can similarly disable this feature using
--   <tt>--no-keyval-maps</tt>:
--   
--   <pre>
--   $ json-to-dhall --no-keyval-maps 'List { mapKey : Text, mapValue : Text }' &lt;&lt;&lt; '{ "foo": "bar" }'
--   Error: Homogeneous JSON map objects cannot be converted to Dhall association lists under --no-keyval-arrays flag
--   </pre>
--   
--   If your schema is a record with a <a>List</a> field and omit that
--   field in the JSON, you'll get an error:
--   
--   <pre>
--   $ json-to-dhall  '{ a : List Natural }' &lt;&lt;&lt; '{}'
--   
--   
--   Error: Key a, expected by Dhall type:
--   List Natural
--   is not present in JSON object:
--   {}
--   </pre>
--   
--   You can use the <tt>--omissible-lists</tt> option to default to an
--   empty list in this case
--   
--   <pre>
--   $ json-to-dhall --omissible-lists  '{ a : List Natural }' &lt;&lt;&lt; '{}'
--   { a = [] : List Natural }
--   </pre>
--   
--   <h2>Optional values and unions</h2>
--   
--   JSON <tt>null</tt> values correspond to <tt>Optional</tt> Dhall
--   values:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; 'null'
--   None &lt;&gt;
--   </pre>
--   
--   ... and the schema inference logic will automatically wrap other
--   values in <tt>Optional</tt> to ensure that the types line up:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; '[ 1, null ]'
--   [ Some 1, None Natural ]
--   </pre>
--   
--   A field that might be absent also corresponds to an <tt>Optional</tt>
--   type:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; '[ { "x": 1 }, { "x": 2, "y": true } ]'
--   [ { x = 1, y = None Bool }, { x = 2, y = Some True } ]
--   </pre>
--   
--   For Dhall union types the correct value will be based on matching the
--   type of JSON expression if you give an explicit type:
--   
--   <pre>
--   $ json-to-dhall 'List &lt; Left : Text | Right : Integer &gt;' &lt;&lt;&lt; '[1, "bar"]'
--   [ &lt; Left : Text | Right : Integer &gt;.Right +1
--   , &lt; Left : Text | Right : Integer &gt;.Left "bar"
--   ]
--   </pre>
--   
--   Also, the schema inference logic will still infer a union anyway in
--   order to reconcile simple types:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; '[ 1, true ]'
--   [ &lt; Bool : Bool | Natural : Natural &gt;.Natural 1
--   , &lt; Bool : Bool | Natural : Natural &gt;.Bool True
--   ]
--   </pre>
--   
--   In presence of multiple potential matches, the first will be selected
--   by default:
--   
--   <pre>
--   $ json-to-dhall '{foo : &lt; Left : Text | Middle : Text | Right : Integer &gt;}' &lt;&lt;&lt; '{ "foo": "bar"}'
--   { foo = &lt; Left : Text | Middle : Text | Right : Integer &gt;.Left "bar" }
--   </pre>
--   
--   This will result in error if <tt>--unions-strict</tt> flag is used,
--   with the list of alternative matches being reported (as a Dhall list)
--   
--   <pre>
--   $ json-to-dhall --unions-strict '{foo : &lt; Left : Text | Middle : Text | Right : Integer &gt;}' &lt;&lt;&lt; '{ "foo": "bar"}'
--   Error: More than one union component type matches JSON value
--   ...
--   Possible matches:
--   &lt; Left : Text | Middle : Text | Right : Integer &gt;.Left "bar"
--   --------
--   &lt; Left : Text | Middle : Text | Right : Integer &gt;.Middle "bar"
--   </pre>
--   
--   <h2>Weakly-typed JSON</h2>
--   
--   If you don't know the JSON's schema in advance, you can decode into
--   the most general schema possible:
--   
--   <pre>
--   $ cat ./schema.dhall
--   https://prelude.dhall-lang.org/JSON/Type
--   </pre>
--   
--   <pre>
--   $ json-to-dhall ./schema.dhall &lt;&lt;&lt; '[ { "foo": null, "bar": [ 1.0, true ] } ]'
--     λ(JSON : Type)
--   → λ(string : Text → JSON)
--   → λ(number : Double → JSON)
--   → λ(object : List { mapKey : Text, mapValue : JSON } → JSON)
--   → λ(array : List JSON → JSON)
--   → λ(bool : Bool → JSON)
--   → λ(null : JSON)
--   → array
--     [ object
--       ( toMap
--           { bar = array [ number 1.0, bool True ]
--           , foo = null
--           }
--       )
--     ]
--   </pre>
--   
--   You can also mix and match JSON fields whose schemas are known or
--   unknown:
--   
--   <pre>
--   $ cat ./mixed.dhall
--   List
--   { foo : Optional Natural
--   , bar : https://prelude.dhall-lang.org/JSON/Type
--   }
--   </pre>
--   
--   <pre>
--   $ json-to-dhall ./mixed.dhall &lt;&lt;&lt; '[ { "foo": null, "bar": [ 1.0, true ] } ]'
--   [ { bar =
--           λ(JSON : Type)
--         → λ(string : Text → JSON)
--         → λ(number : Double → JSON)
--         → λ(object : List { mapKey : Text, mapValue : JSON } → JSON)
--         → λ(array : List JSON → JSON)
--         → λ(bool : Bool → JSON)
--         → λ(null : JSON)
--         → array [ number 1.0, bool True ]
--     , foo =
--         None Natural
--     }
--   ]
--   </pre>
--   
--   The schema inference algorithm will also infer this schema of last
--   resort when unifying a simple type with a record or a list:
--   
--   <pre>
--   $ json-to-dhall &lt;&lt;&lt; '[ 1, [] ]'
--   [ λ(JSON : Type) →
--     λ ( json
--       : { array : List JSON → JSON
--         , bool : Bool → JSON
--         , double : Double → JSON
--         , integer : Integer → JSON
--         , null : JSON
--         , object : List { mapKey : Text, mapValue : JSON } → JSON
--         , string : Text → JSON
--         }
--       ) →
--       json.integer +1
--   , λ(JSON : Type) →
--     λ ( json
--       : { array : List JSON → JSON
--         , bool : Bool → JSON
--         , double : Double → JSON
--         , integer : Integer → JSON
--         , null : JSON
--         , object : List { mapKey : Text, mapValue : JSON } → JSON
--         , string : Text → JSON
--         }
--       ) →
--       json.array ([] : List JSON)
--   ]
--   </pre>
module Dhall.JSONToDhall

-- | Standard parser for options related to the conversion method
parseConversion :: Parser Conversion

-- | JSON-to-dhall translation options
data Conversion
Conversion :: Bool -> Bool -> Bool -> UnionConv -> Bool -> Conversion
[strictRecs] :: Conversion -> Bool
[noKeyValArr] :: Conversion -> Bool
[noKeyValMap] :: Conversion -> Bool
[unions] :: Conversion -> UnionConv
[omissibleLists] :: Conversion -> Bool

-- | Default conversion options
defaultConversion :: Conversion

-- | Parse schema code and resolve imports
resolveSchemaExpr :: Text -> IO ExprX

-- | Check that the Dhall type expression actually has type <tt>Type</tt>
--   &gt;&gt;&gt; :set -XOverloadedStrings &gt;&gt;&gt; import Dhall.Core
--   
--   <pre>
--   &gt;&gt;&gt; typeCheckSchemaExpr id =&lt;&lt; resolveSchemaExpr "List Natural"
--   App List Natural
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; typeCheckSchemaExpr id =&lt;&lt; resolveSchemaExpr "+1"
--   *** Exception:
--   Error: Schema expression is successfully parsed but has Dhall type:
--   Integer
--   Expected Dhall type: Type
--   Parsed expression: +1
--   </pre>
typeCheckSchemaExpr :: (Exception e, MonadCatch m) => (CompileError -> e) -> ExprX -> m ExprX

-- | The main conversion function. Traversing/zipping Dhall <i>type</i> and
--   Aeson value trees together to produce a Dhall <i>term</i> tree, given
--   <a>Conversion</a> options:
--   
--   <pre>
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; import qualified Dhall.Core as D
--   
--   &gt;&gt;&gt; import qualified Dhall.Map as Map
--   
--   &gt;&gt;&gt; import qualified Data.Aeson as Aeson
--   
--   &gt;&gt;&gt; import qualified Data.HashMap.Strict as HM
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; s = D.Record (Map.fromList [("foo", D.Integer)])
--   
--   &gt;&gt;&gt; v = Aeson.Object (HM.fromList [("foo", Aeson.Number 1)])
--   
--   &gt;&gt;&gt; dhallFromJSON defaultConversion s v
--   Right (RecordLit (fromList [("foo",IntegerLit 1)]))
--   </pre>
dhallFromJSON :: Conversion -> ExprX -> Value -> Either CompileError ExprX

-- | A <a>Schema</a> is a subset of the <a>Expr</a> type representing all
--   possible Dhall types that <a>inferSchema</a> could potentially return
data Schema
Bool :: Schema
Natural :: Schema
Integer :: Schema
Double :: Schema
Text :: Schema
List :: Schema -> Schema
Optional :: Schema -> Schema
Record :: RecordSchema -> Schema
Union :: UnionSchema -> Schema
ArbitraryJSON :: Schema

-- | Aeson record type that <a>inferSchema</a> can infer
newtype RecordSchema
RecordSchema :: Map Text Schema -> RecordSchema
[getRecordSchema] :: RecordSchema -> Map Text Schema

-- | A union type that <a>inferSchema</a> can infer
--   
--   This type will have at most three alternatives:
--   
--   <ul>
--   <li>A <tt>Bool</tt> alternative</li>
--   <li>Either a <tt>Natural</tt>, <tt>Integer</tt>, or <tt>Double</tt>
--   alternative</li>
--   <li>A <tt>Text</tt> alternative</li>
--   </ul>
--   
--   These alternatives will always use the same names and types when we
--   convert back to a Dhall type, so we only need to keep track of whether
--   or not each alternative is present.
--   
--   We only store simple types inside of a union since we treat any
--   attempt to unify a simple type with a complex type as a strong
--   indication that the user intended for the schema to be
--   <a>ArbitraryJSON</a>.
data UnionSchema
UnionSchema :: Any -> UnionNumber -> Any -> UnionSchema

-- | <a>True</a> if the union has a <tt>Bool</tt> alternative
[bool] :: UnionSchema -> Any

-- | Up to one numeric alternative
[number] :: UnionSchema -> UnionNumber

-- | <a>True</a> if the union has a <tt>Text</tt> alternative
[text] :: UnionSchema -> Any

-- | Given a JSON <a>Value</a>, make a best-effort guess of what the
--   matching Dhall type should be
--   
--   This is used by <tt>{json,yaml}-to-dhall</tt> if the user does not
--   supply a schema on the command line
inferSchema :: Value -> Schema

-- | Convert a <a>Schema</a> to the corresponding Dhall type
schemaToDhallType :: Schema -> Expr s a
data CompileError
TypeError :: TypeError Src Void -> CompileError
BadDhallType :: ExprX -> ExprX -> CompileError
Mismatch :: ExprX -> Value -> JSONPath -> CompileError
MissingKey :: Text -> ExprX -> Value -> JSONPath -> CompileError
UnhandledKeys :: [Text] -> ExprX -> Value -> JSONPath -> CompileError
NoKeyValArray :: ExprX -> Value -> CompileError
NoKeyValMap :: ExprX -> Value -> CompileError
ContainsUnion :: ExprX -> CompileError
UndecidableUnion :: ExprX -> Value -> [ExprX] -> CompileError
showCompileError :: String -> (Value -> String) -> CompileError -> String
instance GHC.Classes.Eq Dhall.JSONToDhall.UnionConv
instance GHC.Read.Read Dhall.JSONToDhall.UnionConv
instance GHC.Show.Show Dhall.JSONToDhall.UnionConv
instance GHC.Show.Show Dhall.JSONToDhall.Conversion
instance GHC.Classes.Ord Dhall.JSONToDhall.UnionNumber
instance GHC.Classes.Eq Dhall.JSONToDhall.UnionNumber
instance GHC.Enum.Bounded Dhall.JSONToDhall.UnionNumber
instance GHC.Classes.Eq Dhall.JSONToDhall.UnionSchema
instance GHC.Show.Show Dhall.JSONToDhall.CompileError
instance GHC.Exception.Type.Exception Dhall.JSONToDhall.CompileError
instance GHC.Base.Semigroup Dhall.JSONToDhall.RecordSchema
instance GHC.Base.Semigroup Dhall.JSONToDhall.Schema
instance GHC.Base.Monoid Dhall.JSONToDhall.Schema
instance GHC.Base.Semigroup Dhall.JSONToDhall.UnionSchema
instance GHC.Base.Monoid Dhall.JSONToDhall.UnionSchema
instance GHC.Base.Semigroup Dhall.JSONToDhall.UnionNumber
instance GHC.Base.Monoid Dhall.JSONToDhall.UnionNumber
