| |
| Posted by Petar Kirov [ZombineDev] in reply to Ola Fosheim Grøstad | PermalinkReply |
|
Petar Kirov [ZombineDev]
Posted in reply to Ola Fosheim Grøstad
| On Sunday, 28 November 2021 at 20:47:28 UTC, Ola Fosheim Grøstad wrote:
> If there was a majority in favour of D3, with breaking changes, and a strong focus on meta-programming, then it would make a lot of sense to streamline the language.
[..]
What do you think?
From the top of my head, my list looks like this:
-
(Perhaps not D3 worthy - can be done in D2 as well, without removing existing funcitonality) replace all of the current reflection functionality (__traits(..) , is(..) , std.traits , etc.) with a cleaner CTFE-based API, along the lines of Stefan's core.reflect : https://github.com/UplinkCoder/druntime/tree/core_reflect/src/core/reflect
Than add syntax sugar on top, after we develop experience with using it.
-
Type qualifiers. I really like D's type qualifiers, including shared , but after using TypeScript at work for the past 2-3 years, I feel their approach is more flexible - simply offer head-only type qualifiers and build transitive ones on top:
// Generic mapped type:
// https://www.typescriptlang.org/docs/handbook/2/mapped-types.html
type IdentityObject<T> = {
[K in keyof T]: T[K];
};
// Non-transitive read-only (const) type constructor
type ReadOnly<T> = {
readonly [K in keyof T]: T[K];
};
// Deep (transitive) read-only type constructor
type DeepReadOnly<T> = {
readonly [K in keyof T]: DeepReadOnly<T[K]>;
};
Full example in TS playground.
In D3 perhaps this would like this:
// aggregateOf(T) yields `struct`, `class`, `union` or `module`
alias Const(T) = aggregateOf(T)
{
static foreach (fieldName, fieldType; T.fieldsOf)
const fieldType $fieldName;
};
alias TransitiveConst(T) = aggregateOf(T)
{
static foreach (fieldName, fieldType; T.fieldsOf)
const TransitiveConst!fieldType $fieldName;
};
-
Replace interface types and ad hoc Design-by-Introspection patterns like isInputRange , hasMember!(S1, "member") with TypeScript's object types: https://www.typescriptlang.org/docs/handbook/2/objects.html which offer a very powerful, yet elegant and concise way of describing object shapes.
-
Replace ad hoc DIP1000 parameter storage class design with affine types. I haven't given it much thought, but ideally we should be able to write an Affine type constructor in library code and simply use it like as any other type constructor (e.g. tuple, sum type, etc.)
-
Introduce some concept of compile-time dependency resolution / context abstraction (see https://docs.scala-lang.org/scala3/reference/contextual.html) so that things like the current allocator, scheduler, request/response context, etc., can be implicitly provided to improve the ergonomics of such APIs. For example, one could specify that in one scope the current implementation of associative arrays is a GC-managed hashmap, while in other a unique_ptr to red-black tree value container, like std::map , all while using the same K[V] x = [key1: value1] syntax.
|