Nadrieril/dhall-rust

Add a Value type

Closed this issue · 4 comments

A Value type like the one found in other Serde crates would be a really useful addition (I noticed it was available in earlier versions). Specifically the ability to parse to a Value type, and parse that Value type to a concrete type.

A Value type allows for a lot of flexibility and some powerful abstractions, such as dealing with Dhall files of an unknown or variable structure, or partial parsing which can be acted upon and further parsed later.

Rough example of a Value type that I came up with based on the SimpleType enum.

enum Value {
    Bool(bool),
    Natural(u64),
    Integer(i64),
    Double(f64),
    Text(String),
    Optional(Option<Box<Value>>),
    List(Vec<Value>),
    Record(HashMap<String, Box<Value>>),
    Union(HashMap<String, Option<Box<Value>>>),
}

Note: I don't believe that the above enum actually works, but it illustrates the purpose I was trying to convey.

As you noticed, I used to have one such type. The main subtlety is that some cases would need to carry a type around. Typically, an empty list needs to know the types of its elements in order to be usable as a dhall value. That was a bit annoying.
I think I removed it because I didn't think it was very useful. I could add it back since you have a use for it.

I think it's generally useful and makes the library more flexible and more in line with other Serde libraries. So it would be a nice addition.

Sorry to bother you, but has there been any updates on this? It would be a big feature for me.

Not so far. I haven't been working on dhall in a while