digitalmars.D.learn - Why typeof(template) is void?
- mogu (5/5) Jul 19 2016 ```
- Adam D. Ruppe (8/9) Jul 19 2016 Because S isn't a type... think of a template as being like a
- mogu (6/15) Jul 19 2016 So it's a higher kinded type aka type class in Haskell. But D's
- Lodovico Giaretta (4/23) Jul 20 2016 Note that void is a type, while S is not. So you can do:
- mogu (3/6) Jul 20 2016 Thanks very much. I should have noticed this before. T.T
``` struct S(T) {} static assert(is (typeof(S) == void)); ``` Why S's type isn't something like `S: (T) -> S`?
Jul 19 2016
On Wednesday, 20 July 2016 at 01:14:05 UTC, mogu wrote:Why S's type isn't something like `S: (T) -> S`?Because S isn't a type... think of a template as being like a function that returns a type. int foo(int) { return 0; } There, you wouldn't expect typeof(foo) to be int, no, typeof(foo) is a function that returns an int. The template is the same thing - it isn't a type, it is a template that returns a type.
Jul 19 2016
On Wednesday, 20 July 2016 at 01:50:37 UTC, Adam D. Ruppe wrote:On Wednesday, 20 July 2016 at 01:14:05 UTC, mogu wrote:So it's a higher kinded type aka type class in Haskell. But D's reflection cannot get enough information about template's kind. Only a `void` given. It may be inconvenient in distinction between an alias of template and void. The only solution AFAIK is by string of the type property .stringof.Why S's type isn't something like `S: (T) -> S`?Because S isn't a type... think of a template as being like a function that returns a type. int foo(int) { return 0; } There, you wouldn't expect typeof(foo) to be int, no, typeof(foo) is a function that returns an int. The template is the same thing - it isn't a type, it is a template that returns a type.
Jul 19 2016
On Wednesday, 20 July 2016 at 05:54:41 UTC, mogu wrote:On Wednesday, 20 July 2016 at 01:50:37 UTC, Adam D. Ruppe wrote:Note that void is a type, while S is not. So you can do: assert(is(void)) // is(type) returns true assert(!is(S)) // is(template) returns false;On Wednesday, 20 July 2016 at 01:14:05 UTC, mogu wrote:So it's a higher kinded type aka type class in Haskell. But D's reflection cannot get enough information about template's kind. Only a `void` given. It may be inconvenient in distinction between an alias of template and void. The only solution AFAIK is by string of the type property .stringof.Why S's type isn't something like `S: (T) -> S`?Because S isn't a type... think of a template as being like a function that returns a type. int foo(int) { return 0; } There, you wouldn't expect typeof(foo) to be int, no, typeof(foo) is a function that returns an int. The template is the same thing - it isn't a type, it is a template that returns a type.
Jul 20 2016
On Wednesday, 20 July 2016 at 08:01:01 UTC, Lodovico Giaretta wrote:Note that void is a type, while S is not. So you can do: assert(is(void)) // is(type) returns true assert(!is(S)) // is(template) returns false;Thanks very much. I should have noticed this before. T.T
Jul 20 2016