-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Convert bidirectionally between Dhall and CSV files. -- -- Use this package if you want to convert between Dhall expressions and -- CSV. You can use this package as a library or an executable: -- --
-- $ dhall-to-csv <<< '[{ exampleBool = True }]'
-- exampleBool
-- true
-- $ dhall-to-csv <<< '[{ exampleBool = False }]'
-- exampleBool
-- false
--
--
-- Dhall numbers translate to their string representations:
--
--
-- $ dhall-to-csv <<< '[{ exampleInteger = +2 }]'
-- exampleInteger
-- 2
-- $ dhall-to-csv <<< '[{ exampleNatural = 2 }]'
-- exampleNatural
-- 2
-- $ dhall-to-csv <<< '[{ exampleDouble = 2.3 }]'
-- exampleDouble
-- 2.3
--
--
-- Dhall Text translates directly to CSV. Special CSV characters
-- are enclosed by double quotes:
--
--
-- $ dhall-to-csv <<< '[{ exampleText = "ABC" }]'
-- exampleText
-- ABC
-- $ dhall-to-csv <<< '[{ exampleText = "ABC,ABC" }]'
-- exampleText
-- "ABC,ABC"
--
--
-- Dhall Optional values translate to the empty string if absent
-- and the unwrapped value otherwise:
--
--
-- $ dhall-to-csv <<< '[{ exampleOptional = None Natural }]'
-- exampleOptional
--
-- $ dhall-to-csv <<< '[{ exampleOptional = Some 1 }]'
-- exampleOptional
-- 1
--
--
-- Dhall unions translate to the wrapped value or the name of the field
-- (in case it is an empty field):
--
--
-- $ dhall-to-csv <<< "[{ exampleUnion = < Left | Right : Natural>.Left }]"
-- exampleUnion
-- Left
-- $ dhall-to-csv <<< "[{ exampleUnion = < Left | Right : Natural>.Right 2 }]"
-- exampleUnion
-- 2
--
--
-- Also, all Dhall expressions are normalized before translation to CSV:
--
--
-- $ dhall-to-csv <<< "[{ equality = True == False }]"
-- equality
-- false
--
module Dhall.Csv
-- | Convert a Dhall expression (with resolved imports) to an sequence of
-- CSV NamedRecords.
dhallToCsv :: Expr s Void -> Either CompileError (Seq NamedRecord)
-- | Convert a Text with Dhall code to a list of
-- NamedRecords.
codeToValue :: Maybe FilePath -> Text -> IO [NamedRecord]
-- | This is the exception type for errors that can arise when converting
-- from Dhall to CSV.
--
-- It contains information on the specific cases that might fail to give
-- a better insight.
data CompileError
instance GHC.Show.Show Dhall.Csv.CompileError
instance GHC.Exception.Type.Exception Dhall.Csv.CompileError
module Dhall.Csv.Util
-- | Utility to convert a list of NamedRecord to Text formatted as
-- a CSV.
encodeCsvDefault :: [NamedRecord] -> Text
-- | Utility to decode a CSV into a list of records. Must specify whether
-- the CSV to decode has header or not.
decodeCsvDefault :: Bool -> Text -> Either String [NamedRecord]
-- | Convert CSV data to Dhall providing an expected Dhall type necessary
-- to know which type will be interpreted.
--
-- The translation process will produce a Dhall expression where its type
-- is a List of records and the type of each field of the
-- records is one of the following:
--
--
-- $ cat example.csv
-- example
-- 1
-- $ csv-to-dhall 'List { example : Integer }' < example.csv
-- [{ example = +1 }]
--
--
-- When using the csv-to-dhall executable you can specify that
-- the CSV you want to translate does not have a header with the flag
-- `--no-header`. In this case the resulting record fields will be named
-- _1, _2, ... in the same order they were in the input
-- CSV. You must still provide the expected Dhall type taking this into
-- consideration.
--
--
-- $ cat no-header-example.csv
-- 1,3.14,Hello
-- -1,2.68,Goodbye
-- $ csv-to-dhall --no-header 'List { _1 : Integer, _2 : Double, _3 : Text } < no-header-example.csv
-- [ { _1 = +1, _2 = 3.14, _3 = "Hello" }
-- , { _1 = -1, _2 = 2.68, _3 = "Goodbye" }
-- ]
--
--
--
-- $ cat example.csv
-- exampleBool
-- true
-- false
-- $ csv-to-dhall 'List { exampleBool : Bool }' < example.csv
-- [ { exampleBool = True }, { exampleBool = False } ]
--
--
-- Numeric strings can translate to Dhall numbers:
--
--
-- $ cat example.csv
-- exampleNatural,exampleInt,exampleDouble
-- 1,2,3
-- 0,-2,3.14
-- 0,+2,-3.14
-- $ csv-to-dhall 'List { exampleNatural : Natural, exampleInt : Integer, exampleDouble : Double }' < example.csv
-- [ { exampleNatural = 1, exampleInt = +2, exampleDouble = 3.0 }
-- , { exampleNatural = 0, exampleInt = -2, exampleDouble = 3.14 }
-- , { exampleNatural = 0, exampleInt = +2, exampleDouble = -3.14 }
-- ]
--
--
-- Every CSV Field can translate directly to Dhall Text:
--
--
-- $ cat example.csv
-- exampleText
-- Hello
-- false
--
-- ","
-- $ csv-to-dhall 'List { exampleText : Text }' < example.csv
-- [ { exampleText = "Hello" }
-- , { exampleText = "false" }
-- , { exampleText = "" }
-- , { exampleText = "," }
-- ]
--
--
--
-- $ cat example.csv
-- exampleUnion
-- Hello
-- 1
-- 1.11
-- $ csv-to-dhall 'List { exampleUnion : <Hello | Nat : Natural | Dob : Double> }' < example.csv
-- [ { exampleUnion = <Hello | Nat : Natural | Dob : Double>.Hello }
-- , { exampleUnion = <Hello | Nat : Natural | Dob : Double>.Nat 1 }
-- , { exampleUnion = <Hello | Nat : Natural | Dob : Double>.Dob 1.11 }
-- ]
--
--
-- Optional values can be either missing or have the expected value. The
-- missing value is represented by the empty string. If a field's
-- expected value is an Optional and the field is not in the CSV, then
-- all the values will be None.
--
--
-- $ cat example.csv
-- exampleOptional
-- 1
--
-- 3
-- $ csv-to-dhall 'List { exampleOptional : Optional Natural, exampleMissing : Optional Natural }' < example.csv
-- [ { exampleOptional = Some 1, exampleMissing = None Natural }
-- , { exampleOptional = None Natural, exampleMissing = None Natural }
-- , { exampleOptional = Some 3, exampleMissing = None Natural }
-- ]
--
module Dhall.CsvToDhall
-- | Convert a list of CSV NameRecord to a Dhall expression given
-- the expected Dhall Type of the output.
dhallFromCsv :: Conversion -> ExprX -> [NamedRecord] -> Either CompileError ExprX
-- | Standard parser for options related to the conversion method
parseConversion :: Parser Conversion
-- | Default conversion options
defaultConversion :: Conversion
-- | Parse schema code and resolve imports
resolveSchemaExpr :: Text -> IO ExprX
-- | Check that the Dhall type expression actually has type Type
typeCheckSchemaExpr :: (Exception e, MonadCatch m) => (CompileError -> e) -> ExprX -> m ExprX
-- | CSV-to-dhall translation options
data Conversion
Conversion :: Bool -> UnionConv -> Conversion
[strictRecs] :: Conversion -> Bool
[unions] :: Conversion -> UnionConv
-- | This is the exception type for errors that can arise when converting
-- from CSV to Dhall.
--
-- It contains information on the specific cases that might fail to give
-- a better insight.
data CompileError
Unsupported :: ExprX -> CompileError
NotAList :: ExprX -> CompileError
NotARecord :: ExprX -> CompileError
TypeError :: TypeError Src Void -> CompileError
BadSchemaType :: ExprX -> ExprX -> CompileError
MissingField :: Text -> CompileError
UnhandledFields :: [Text] -> CompileError
Mismatch :: ExprX -> Text -> Text -> CompileError
ContainsUnion :: ExprX -> CompileError
UndecidableUnion :: ExprX -> Text -> Text -> [ExprX] -> CompileError
UndecidableMissingUnion :: ExprX -> Text -> [ExprX] -> CompileError
UnicodeError :: UnicodeException -> CompileError
instance GHC.Classes.Eq Dhall.CsvToDhall.UnionConv
instance GHC.Read.Read Dhall.CsvToDhall.UnionConv
instance GHC.Show.Show Dhall.CsvToDhall.UnionConv
instance GHC.Show.Show Dhall.CsvToDhall.Conversion
instance GHC.Show.Show Dhall.CsvToDhall.CompileError
instance GHC.Exception.Type.Exception Dhall.CsvToDhall.CompileError