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

How to assert the type of loaded value? #92

Open koterpillar opened 2 years ago

koterpillar commented 2 years ago

In Haskell bindings, I can use some typeclasses to load a Dhall value of an expected type (official example). I would like to do the same in Python:

@dataclass
class Example:
    foo: int
    bar: list[double]

x = dhall.load(open('./config'), type_=Example)

The intended result:

How do I do this with dhall-python? If it's not currently possible, any pointers on implementation?