dhall-csv-1.0.2: Convert bidirectionally between Dhall and CSV files.
Safe HaskellNone
LanguageHaskell2010

Dhall.Csv

Contents

Description

This library exports two functions: dhallToCsv and codeToValue. The former converts a Dhall expression (with imports resolved already) into a sequence of CSV NamedRecords (from the cassava library) while the latter converts a Text containing Dhall code into a list of CSV NamedRecords.

Not all Dhall expressions can be converted to CSV since CSV is not a programming language. The only things you can convert are Lists of records where each field is one of the following types:

  • Bools
  • Naturals
  • Integers
  • Doubles
  • Text values
  • Optional (of valid field types)
  • unions (of empty alternatives or valid record field types)

Dhall Bools translate to either `"true"` or `"false"` in all lowercase letters:

$ 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
Synopsis

Documentation

dhallToCsv :: Expr s Void -> Either CompileError (Seq NamedRecord) Source #

Convert a Dhall expression (with resolved imports) to an sequence of CSV NamedRecords.

codeToValue :: Maybe FilePath -> Text -> IO [NamedRecord] Source #

Convert a Text with Dhall code to a list of NamedRecords.

Exceptions

data CompileError Source #

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.