Safe Haskell | None |
---|---|
Language | Haskell2010 |
This library exports two functions: dhallToCsv
and codeToValue
.
The former converts a Dhall expression (with imports resolved already) into a
sequence of CSV NamedRecord
s (from the cassava
library) while the latter
converts a Text
containing Dhall code into a list of CSV NamedRecord
s.
Not all Dhall expressions can be converted to CSV since CSV is not a
programming language. The only things you can convert are List
s of
records where each field is one of the following types:
Bool
sNatural
sInteger
sDouble
sText
valuesOptional
(of valid field types)- unions (of empty alternatives or valid record field types)
Dhall Bool
s 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
- dhallToCsv :: Expr s Void -> Either CompileError (Seq NamedRecord)
- codeToValue :: Maybe FilePath -> Text -> IO [NamedRecord]
- data CompileError
Documentation
dhallToCsv :: Expr s Void -> Either CompileError (Seq NamedRecord) Source #
Convert a Dhall expression (with resolved imports) to an
sequence of CSV NamedRecord
s.
codeToValue :: Maybe FilePath -> Text -> IO [NamedRecord] Source #
Convert a Text
with Dhall code to a list of NamedRecord
s.
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.
Instances
Show CompileError Source # | |
Defined in Dhall.Csv showsPrec :: Int -> CompileError -> ShowS # show :: CompileError -> String # showList :: [CompileError] -> ShowS # | |
Exception CompileError Source # | |
Defined in Dhall.Csv |