s-zeng / dhall-python

Up-to-date and maintained python bindings for dhall, a functional configuration language
https://pypi.org/project/dhall/
Apache License 2.0
44 stars 6 forks source link

Python representation of Optional and Unions #6

Open s-zeng opened 3 years ago

s-zeng commented 3 years ago

We should have types/objects in Python that we can use to serialize into dhall unions. Optionally, we can have a flag that lets dhall deserialize into such types.

i.e. desired ux should be something like:

>>> import dhall
>>> dhall.dumps([dhall.Some(5), None])
'[Some 5, None Natural]'
nickray commented 3 years ago

There are several Python libraries that implement Options and Results in the Rust style. Maybe one of those should be used? Although it seems (to me) there's no clear winner one should pick.

s-zeng commented 3 years ago

There's no clear winner, and it's also quite easy to implement ourselves on the python side. It'll just take some fiddling on the rust-side to get it to line up w/ whatever data struct we choose. I can look into this when I have a bit more time but until then I'll probably defer to the choice of whoever submits a working PR