dhall-lang / dhall-json

This repository has moved to https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-json
BSD 3-Clause "New" or "Revised" License
65 stars 6 forks source link

Ambiguous Unions in JSON output? #10

Closed sordina closed 6 years ago

sordina commented 6 years ago

I could be wrong, but are the JSON representation of unions ambiguous?

Example:

~/temp/dhall-examples
$ cat type3.dhall
[ < Left = +1 | Right : Bool | Other : Natural >
, < Other = +3 | Right : Bool | Left : Natural >
] : List < Left : Natural | Right : Bool | Other : Natural >

~/temp/dhall-examples
$ dhall-to-json < type3.dhall
[1,3]
sordina commented 6 years ago

Oops I accidentally closed the issue! Sorry!

Gabriella439 commented 6 years ago

This is intentional. See:

https://github.com/dhall-lang/dhall-json/issues/2

... and:

https://github.com/dhall-lang/dhall-lang/wiki/Getting-started%3A-Generate-JSON-or-YAML#unions

sordina commented 6 years ago

Ah interesting, it certainly makes sense for flexibly generating JSON, but what about the other direction? Say I wanted to interpret some Dhall generated JSON with Haskell, is the idea that you would explicitly create a 'tagged' output representation if the output could be ambiguous?

Gabriella439 commented 6 years ago

So I don't have plans to convert in the other direction, but if I did I would most likely be strict in the conversion and reject weakly typed JSON

sordina commented 6 years ago

Thanks for the insight, I'll close the issue :)

Gabriella439 commented 6 years ago

You're welcome! 🙂