$ dhall-to-json <<< "Some 1"
1
$ dhall-to-json <<< "None"
Error: Cannot translate to JSON
Not exactly sure what the best approach is, but it would be nice for my go package that uses dhall-to-json to be able to use optionals.
$ dhall-to-json <<< "None"
I believe you want something like None Natural -- the type is required.
My mistake :)
@singpolyma The way None works in the AST, you could also make None valid by itself, no?
β> @singpolyma The way None works in the AST, you could also make None valid by itself, no?
By itself it is valid -- it's a function from a type to the empty optional of that type.β
By itself it is valid -- it's a function from a type to the empty optional of that type.β
I know, but the AST doesnβt express that fact, so you could re-interpret it. Admittedly that would be a crude hack and go against dhall semantics.
Alternatively, a better error message would help. :P
I don't think we should translate a bare None to null, but a better error message would be very easy to add. I will reopen this and make that the scope of this issue
The fix is up here: https://github.com/dhall-lang/dhall-haskell/pull/895
Sorry for the late comment but it might clarify things a bit for some of us: None is technically a function taking a type as its argument:
$ dhall --annotate <<< 'None'
None : β(A : Type) β Optional A
$ dhall --annotate <<< 'None Integer'
None Integer : Optional Integer
In other words, it is actually somewhat different from Nothing in Haskell, so that e.g. None : Optional Integer doesn't make sense (while Some +1 : Optional Integer does!).
@antislava: Here is the new error message from the pull request that I have out for this:
$ dhall-to-json <<< 'None'
Error: A bare β°Noneβ± is not valid
Explanation: The conversion to JSON/YAML does not accept β°Noneβ± in isolation as
a valid way to represent β°nullβ±. In Dhall, β°Noneβ± is a function whose input is
a type and whose output is an absent value of that type.
For example:
βββββββββββββββββββββββββββββββββββ This is a function whose result is an
β None : β(a : Type) β Optional a β β°Optionalβ± value, but the function
βββββββββββββββββββββββββββββββββββ itself is not a valid β°Optionalβ± value
βββββββββββββββββββββββββββββββββββ
β None Natural : Optional Natural β This is a valid β°Optionalβ± value (an
βββββββββββββββββββββββββββββββββββ absent β°Naturalβ± number in this case)
The conversion to JSON/YAML only translates the latter form to β°nullβ±.
Most helpful comment
@antislava: Here is the new error message from the pull request that I have out for this: