-- 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> module if you want to use this package
--   as a library</li>
--   <li>Use the <tt>dhall-to-json</tt> or <tt>dhall-to-yaml</tt> programs
--   from this package if you want an executable</li>
--   </ul>
--   
--   The <a>Dhall.JSON</a> module also contains instructions for how to use
--   this package
@package dhall-json
@version 1.3.0


-- | 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><pre>Text</pre></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 Integer'
--   [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; '[] : Optional Integer'
--   null
--   $ dhall-to-json &lt;&lt;&lt; '[1] : Optional Integer'
--   1
--   </pre>
--   
--   Dhall records translate to JSON records:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; '{ foo = 1, bar = True }'
--   {"foo":1,"bar":true}
--   </pre>
--   
--   Dhall unions translate to the wrapped value:
--   
--   <pre>
--   $ dhall-to-json &lt;&lt;&lt; "&lt; Left = +2 | Right : Natural&gt;"
--   2
--   $ cat config
--   [ &lt; Person = { age = +47, name = "John" }
--     | Place  : { location : Text }
--     &gt;
--   , &lt; Place  = { location = "North Pole" }
--     | Person : { age : Natural, name : Text }
--     &gt;
--   , &lt; Place  = { location = "Sahara Desert" }
--     | Person : { age : Natural, name : Text }
--     &gt;
--   , &lt; Person = { age = +35, name = "Alice" }
--     | Place  : { location : Text }
--     &gt;
--   ]
--   $ 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;
--   
--   in  let example = constructors Example
--   
--   in  let Nesting = &lt; Inline : {} | Nested : Text &gt;
--   
--   in  let nesting = constructors Nesting
--   
--   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 store underneath a field named <tt>nestedField</tt>. For
--   example, this code:
--   
--   <pre>
--       let Example = &lt; Left : { foo : Natural } | Right : { bar : Bool } &gt;
--   
--   in  let example = constructors Example
--   
--   in  let Nesting = &lt; Inline : {} | Nested : Text &gt;
--   
--   in  let nesting = constructors Nesting
--   
--   in  { field    = "name"
--       , nesting  = nesting.Nested "value"
--       , contents = example.Left { foo = 2 }
--       }
--   </pre>
--   
--   ... produces this JSON:
--   
--   <pre>
--   {
--     "name": "Left",
--     "value": {
--       "foo": 2
--     }
--   }
--   </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 Dhall.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 Data.Aeson.encode it
--   Right "{\"foo\":1,\"bar\":\"ABC\"}"
--   </pre>
dhallToJSON :: Expr s X -> 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

-- | Parser for command-line options related to omitting fields
parseOmission :: 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

-- | 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 X -> Expr s X

-- | 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 X -> Either CompileError (Expr s X)

-- | Convert a piece of Text carrying a Dhall inscription to an equivalent
--   JSON Value
--   
--   <pre>
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; import Dhall.Core
--   
--   &gt;&gt;&gt; Dhall.JSON.codeToValue "(stdin)" "{ a = 1 }"
--   
--   &gt;&gt;&gt; Object (fromList [("a",Number 1.0)])
--   </pre>
codeToValue :: Conversion -> SpecialDoubleMode -> Text -> Text -> IO 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 X X -> CompileError
SpecialDouble :: Double -> CompileError
BareNone :: CompileError
instance GHC.Show.Show Dhall.JSON.CompileError
instance GHC.Exception.Type.Exception Dhall.JSON.CompileError


-- | Convert JSON data to Dhall given a Dhall <i>type</i> expression
--   necessary to make the translation unambiguous.
--   
--   Reasonable requirements for conversion are:
--   
--   <ol>
--   <li>The Dhall type expression <tt><i>t</i></tt> passed as an argument
--   to <tt>json-to-dhall</tt> should be a valid type of the resulting
--   Dhall expression</li>
--   <li>A JSON data produced by the corresponding <tt>dhall-to-json</tt>
--   from the Dhall expression of type <tt><i>t</i></tt> should (under
--   reasonable assumptions) reproduce the original Dhall expression using
--   <tt>json-to-dhall</tt> with type argument <tt><i>t</i></tt></li>
--   </ol>
--   
--   Only a subset of Dhall types consisting of all the primitive types as
--   well as <tt>Optional</tt>, <tt>Union</tt> and <tt>Record</tt>
--   constructs, is used for reading JSON data:
--   
--   <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>s</li>
--   <li><tt>List</tt>s</li>
--   <li><tt>Optional</tt> values</li>
--   <li>unions</li>
--   <li>records</li>
--   </ul>
--   
--   This library can be used to implement an executable which takes any
--   data serialisation format which can be parsed as an Aeson
--   <tt>Value</tt> and converts the result to a Dhall value. One such
--   executable is <tt>json-to-dhall</tt> which is used in the examples
--   below.
--   
--   <h2>Primitive types</h2>
--   
--   JSON <tt>Bool</tt>s translate to Dhall bools:
--   
--   <pre>
--   $ json-to-dhall Bool &lt;&lt;&lt; 'true'
--   True
--   $ json-to-dhall Bool &lt;&lt;&lt; 'false'
--   False
--   </pre>
--   
--   JSON numbers translate to Dhall numbers:
--   
--   <pre>
--   $ json-to-dhall Integer &lt;&lt;&lt; 2
--   +2
--   $ json-to-dhall Natural &lt;&lt;&lt; 2
--   2
--   $ json-to-dhall Double &lt;&lt;&lt; -2.345
--   -2.345
--   </pre>
--   
--   Dhall <tt>Text</tt> corresponds to JSON text:
--   
--   <pre>
--   $ json-to-dhall Text &lt;&lt;&lt; '"foo bar"'
--   "foo bar"
--   </pre>
--   
--   <h2>Lists and records</h2>
--   
--   Dhall <tt>List</tt>s correspond to JSON lists:
--   
--   <pre>
--   $ json-to-dhall 'List Integer' &lt;&lt;&lt; '[1, 2, 3]'
--   [ +1, +2, +3 ]
--   </pre>
--   
--   Dhall <b>records</b> correspond to JSON records:
--   
--   <pre>
--   $ json-to-dhall '{foo : List Integer}' &lt;&lt;&lt; '{"foo": [1, 2, 3]}'
--   { foo = [ +1, +2, +3 ] }
--   </pre>
--   
--   Note, that by default, only the fields required by the Dhall type
--   argument are parsed (as you commonly will not need all the data), the
--   remaining ones being ignored:
--   
--   <pre>
--   $ json-to-dhall '{foo : List Integer}' &lt;&lt;&lt; '{"foo": [1, 2, 3], "bar" : "asdf"}'
--   { foo = [ +1, +2, +3 ] }
--   </pre>
--   
--   If you do need to make sure that Dhall fully reflects JSON record data
--   comprehensively, <tt>--records-strict</tt> flag should be used:
--   
--   <pre>
--   $ json-to-dhall --records-strict '{foo : List Integer}' &lt;&lt;&lt; '{"foo": [1, 2, 3], "bar" : "asdf"}'
--   Error: Key(s) @bar@ present in the JSON object but not in the corresponding Dhall record. This is not allowed in presence of --records-strict:
--   </pre>
--   
--   By default, JSON key-value arrays will be converted to Dhall records:
--   
--   <pre>
--   $ json-to-dhall '{ a : Integer, b : Text }' &lt;&lt;&lt; '[{"key":"a", "value":1}, {"key":"b", "value":"asdf"}]'
--   { a = +1, b = "asdf" }
--   </pre>
--   
--   Attempting to do the same with <tt>--no-keyval-arrays</tt> on will
--   result in error:
--   
--   <pre>
--   $ json-to-dhall --no-keyval-arrays '{ a : Integer, 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>
--   
--   Conversion of the homogeneous JSON maps to the corresponding Dhall
--   association lists by default:
--   
--   <pre>
--   $ json-to-dhall 'List { mapKey : Text, mapValue : Text }' &lt;&lt;&lt; '{"foo": "bar"}'
--   [ { mapKey = "foo", mapValue = "bar" } ]
--   </pre>
--   
--   Flag <tt>--no-keyval-maps</tt> switches off this mechanism (if one
--   would ever need it):
--   
--   <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>
--   
--   <h2>Optional values and unions</h2>
--   
--   Dhall <tt>Optional</tt> Dhall type allows null or missing JSON values:
--   
--   <pre>
--   $ json-to-dhall "Optional Integer" &lt;&lt;&lt; '1'
--   Some +1
--   </pre>
--   
--   <pre>
--   $ json-to-dhall "Optional Integer" &lt;&lt;&lt; null
--   None Integer
--   </pre>
--   
--   <pre>
--   $ json-to-dhall '{ a : Integer, b : Optional Text }' &lt;&lt;&lt; '{ "a": 1 }'
--   </pre>
--   
--   { a = +1, b = None Text }
--   
--   For Dhall <b>union types</b> the correct value will be based on
--   matching the type of JSON expression:
--   
--   <pre>
--   $ json-to-dhall 'List &lt; Left : Text | Right : Integer &gt;' &lt;&lt;&lt; '[1, "bar"]'
--   [ &lt; Left : Text | Right : Integer &gt;.Right +1
--   </pre>
--   
--   , <a>: Text | Right : Integer</a>.Left "bar" ]
--   
--   <pre>
--   $ json-to-dhall '{foo : &lt; Left : Text | Right : Integer &gt;}' &lt;&lt;&lt; '{ "foo": "bar" }'
--   { foo = &lt; Left : Text | Right : Integer &gt;.Left "bar" }
--   </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:
--   </pre>
--   
--   <a>: Text | Middle : Text | Right : Integer</a>.Left "bar" &gt;
--   -------- <a>: Text | Middle : Text | Right : Integer</a>.Middle "bar"
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 -> Conversion
[strictRecs] :: Conversion -> Bool
[noKeyValArr] :: Conversion -> Bool
[noKeyValMap] :: Conversion -> Bool
[unions] :: Conversion -> UnionConv

-- | Default conversion options
defaultConversion :: Conversion

-- | Parse schema code to a valid Dhall expression and check that its type
--   is actually Type
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 succesfully 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<i>zipping Dhall </i>type<i>
--   and Aeson value trees together to produce a Dhall </i>term/ 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 A
--   
--   &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 = A.Object (HM.fromList [("foo", A.Number 1)])
--   
--   &gt;&gt;&gt; dhallFromJSON defaultConversion s v
--   Right (RecordLit (fromList [("foo",IntegerLit 1)]))
--   </pre>
dhallFromJSON :: Conversion -> ExprX -> Value -> Either CompileError ExprX
data CompileError
TypeError :: TypeError Src X -> CompileError
BadDhallType :: ExprX -> ExprX -> CompileError
Mismatch :: ExprX -> Value -> CompileError
MissingKey :: Text -> ExprX -> Value -> CompileError
UnhandledKeys :: [Text] -> ExprX -> Value -> 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.Show.Show Dhall.JSONToDhall.Conversion
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.CompileError
instance GHC.Exception.Type.Exception Dhall.JSONToDhall.CompileError

module Dhall.Yaml

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

-- | Transform yaml representation into dhall
yamlToJson :: ByteString -> Either String Value
