Is there any chance to introduce concepts/traits/typeClasses in dlang?

rikki cattermole rikki at cattermole.co.nz
Sun Dec 15 16:42:23 UTC 2019


The easiest D example for this family of language features is ranges IMO.

Turn:

auto map(alias func, IR)(IR input) if (...) {
	struct Voldemort {
		...
	}

	return ...;
}

Into:

auto:InputRange map(alias func, IR:InputRange)(IR input) if (...) {
	struct Voldemort {
		...
	}

	return ...;
}

That is the static introspection capabilities.
For dynamic:

// typeof(input) is still templated, its just hidden, since only the 
template arguments need deducing
InputRange!ElementType map(alias func)(auto:InputRange input) if (...) {
	struct Voldemort {
		...
	}

	return ...; // auto construction of an InputRange instance with 
deduction of what ElementType is.
}


More information about the Digitalmars-d mailing list