What type functions mean on a language level
sighoya
sighoya at gmail.com
Wed Jan 6 13:52:39 UTC 2021
On Saturday, 2 January 2021 at 09:28:15 UTC, Stefan Koch wrote:
>I guess I could create the name to just be "LinkedList(f(x,
>g(y), j(z)))" where f(x, g(y), j(z))) is eagerly evaluated, and
>then the name is LinkedList(float) or something like that.
>But that seems like reinventing templates with all their
>troubles...
>perhaps it's still worthwhile though?
If we allow a __type__ in type position, indirectly or directly,
we're able to implement generics known from other languages, e.g.:
```
method(__type__ type)(type value){...}
```
vs
```
method(T)(T value){...}
```
Although I appreciate a more idiomatic form of generics, we would
provide two ways to do the same thing.
Moreover, __type__ generics have, as you said, to be eagerly
checked, and we are forced to provide full constraints with the
potential to forcefully up propagate them.
Even though this is the more correct way to set up things it
doesn't feel very D-ish or kiss like, don't know if its worth the
cost.
Theoretically, template systems could provide better errors than
generic systems because their error messages would be of concrete
kind while those of generics are of abstract kind.
The only problem is how to back propagate template error messages
such they are meaningful in downstream code, it's possible, but
it is a lot of work.
More information about the Digitalmars-d
mailing list