Re:The Vale Programming Language
by mumblemumble on Friday November 20, 2020 @11:20AM
(#25161859)
> Rust, you have to name an interface, but you can’t actually create new instances of the concrete type returned by the function.
I think that's the distinction that really matters. The thing that's neat about Voldemort types, and gives them their interesting properties that are distinct from anonymous types, is that they have no name at all. Not even an interface or trait name.
What would be a concrete use case which benefits from this? I am not experienced with D, but it just seems like it would make code more obscure
Re:The Vale Programming Language
by mumblemumble on Friday November 20, 2020 @01:24PM
(#25163265)
There's a bit more explanation on the D wiki: https://wiki.dlang.org/Voldemort_types
I don't really intend to say whether they are better or worse than other ways of accomplishing similar things. Just that they're different.
Yes, from that explanation it sounds like they are equivalent to Rust’s impl return types.
Note that interfaces in Rust are not types, they do not name types. A value cannot have interface type. What happens when you return an “impl” type is that you return some unspecified type, but that type must implement the specified interface.
You could translate the D example to:
trait HasGetValue {
fn get_value(&self) -> i32;
}
fn create_voldemort_type(value: i32) -> impl HasGetValue {
...
}
The “create_voldemort_type” function simply returns a value of unspecified type. As far as I can tell, this is equivalent to the D code, except it doesn’t use type inference for the function type.Not really. Part of the point of voldemort types is that no information about the type is 'leaked' outside the function. In this case, the trait 'HasGetValue' is leaked and can be used by other code.
When would you want to have an interface such that nothing about the return type of a function is known to the outside world? I'm genuinely asking; I just don't understand the utility of this concept.
Re:The Vale Programming Language
by mumblemumble on Friday November 20, 2020 @06:32PM
(#25166432)
I don't think anyone's trying to argue about whether it's better or worse than the Rust concept. Just that it's subtly different.
I'm not interested in comparing it to the rust concept. I'm just curious why this is something people find valuable in D, and why another commenter would call it a feature D "would be ruined without"
Re:The Vale Programming Language
by bobthebuilders on Saturday November 21, 2020 @02:20AM
(#25168323)
The commentor is just mistaken. The two do the exact same thing.
Not true in Rust, because the type returned by the function is a concrete type.
I think we may be overloading “name” here, a bit. If you return an “impl” in Rust, you have to name an interface, but you can’t actually create new instances of the concrete type returned by the function.