Is there any chance to introduce concepts/traits/typeClasses in dlang?
mipri
mipri at minimaltype.com
Sun Dec 15 16:36:00 UTC 2019
On Sunday, 15 December 2019 at 16:11:31 UTC, sighoya wrote:
> TypeClasses aren't a static solution only, they can also be
> used as existentials allowing dynamic dispatch
...
> A possible look how flexible it can be taken from the nim
> language
> Link:
> https://nim-lang.org/docs/manual_experimental.html#concepts
From that page:
The concept is a match if:
- all of the expressions within the body can be compiled for
the tested type
- all statically evaluable boolean expressions in the body must
be true
Looks to me like this is just a way of attaching D's static
constraints to a type, so that
void push(T)(Stack!T stack, T item) { }
becomes (something like, for inference's sake S shouldn't be
separate I think):
void push(S,T)(S!T stack, T item) if (a bunch of !S tests) { }
What does this have to do with dynamic dispatch? How is this
not already something you can do with an isStack!S test?
> Nevertheless, we can't changed everything in a
> backward-compatible way. I hope some of you are happy to
> discuss ideas about concepts in this thread.
I don't understand what you're trying to do, and these A, B, C,
D examples take a lot effort to read, vs. Comparable and Stack
examples.
What I'd prefer is
// valid current-D example:
...
// but look at (how verbose this is | how expensive this is |
// how much effort it'd take to adapt this in Y direction |
// &c)!
vs.
// valid improved-D example:
More information about the Digitalmars-d
mailing list