Jump to page: 1 2
Thread overview
[RFC] std.experimental.concepts
Jul 24, 2015
Shammah Chancellor
Jul 24, 2015
deadalnix
Jul 25, 2015
deadalnix
Jul 25, 2015
deadalnix
Jul 26, 2015
Tofu Ninja
Jul 26, 2015
Tofu Ninja
Jul 27, 2015
Tofu Ninja
Jul 27, 2015
deadalnix
Jul 29, 2015
Shammah Chancellor
Jul 25, 2015
Daniel N
Jul 25, 2015
Martin Nowak
Jul 25, 2015
Rikki Cattermole
Jul 25, 2015
Daniel N
Jul 26, 2015
Timon Gehr
July 24, 2015
I put up a PR for phobos awhile ago for concepts as a library to kind of start the discussion around concepts.   There seemed to be some interest around the PR, so I have rebased it and fixed the formatting.

Please take a look: https://github.com/D-Programming-Language/phobos/pull/2627

-Shammah
July 24, 2015
On Friday, 24 July 2015 at 19:56:55 UTC, Shammah Chancellor wrote:
> I put up a PR for phobos awhile ago for concepts as a library to kind of start the discussion around concepts.   There seemed to be some interest around the PR, so I have rebased it and fixed the formatting.
>
> Please take a look: https://github.com/D-Programming-Language/phobos/pull/2627
>
> -Shammah

Doing it as a library would miss a lot of the point of concepts :
 - Compiler can do a fair amount of semantic analysis on template before instantiating them. This work is done once rather than repeating it a every template instantiation.
 - It allow for much more clearer error messages. Anyone having to maintain some meta code will understand what I'm talking about here.
 - It make compile time and runtime polymorphism more alike. I do think we'd all agree that Andrei approach to mention template arguments as compile time arguments and go from there is a good move. Concept would be the same move, but for typing. By reusing common language constructs (C++ failed to use that opportunity) for instance.

July 25, 2015
On 7/24/15 7:13 PM, deadalnix wrote:
> On Friday, 24 July 2015 at 19:56:55 UTC, Shammah Chancellor wrote:
>> I put up a PR for phobos awhile ago for concepts as a library to kind
>> of start the discussion around concepts.   There seemed to be some
>> interest around the PR, so I have rebased it and fixed the formatting.
>>
>> Please take a look:
>> https://github.com/D-Programming-Language/phobos/pull/2627
>>
>> -Shammah
>
> Doing it as a library would miss a lot of the point of concepts :
>   - Compiler can do a fair amount of semantic analysis on template
> before instantiating them. This work is done once rather than repeating
> it a every template instantiation.

Interesting.

>   - It allow for much more clearer error messages. Anyone having to
> maintain some meta code will understand what I'm talking about here.

Agreed, though I would more if "much" were dropped.

>   - It make compile time and runtime polymorphism more alike. I do think
> we'd all agree that Andrei approach to mention template arguments as
> compile time arguments and go from there is a good move. Concept would
> be the same move, but for typing. By reusing common language constructs
> (C++ failed to use that opportunity) for instance.

Meh to that.

Now stack these advantages against the advantages of template constraints. It's a landslide.


Andrei
July 25, 2015
On Friday, 24 July 2015 at 19:56:55 UTC, Shammah Chancellor wrote:
> I put up a PR for phobos awhile ago for concepts as a library to kind of start the discussion around concepts.   There seemed to be some interest around the PR, so I have rebased it and fixed the formatting.
>
> Please take a look: https://github.com/D-Programming-Language/phobos/pull/2627
>
> -Shammah

For those who are on a sugar-rush from Concepts, maybe this is a fun trick?

It almost works, if only IFTI was smart enough to deal with eponymous identity templates.

========================================
int fun(T)(T t) if(is(typeof(T.Put)))
{
}
========================================
template Putty(T)
{
  static assert(is(typeof(T.Put)));

  alias Putty = T;
}
void fun(T)(Putty!T t)
{
}
========================================

July 25, 2015
On Saturday, 25 July 2015 at 14:06:05 UTC, Daniel N wrote:
> On Friday, 24 July 2015 at 19:56:55 UTC, Shammah Chancellor wrote:
>> I put up a PR for phobos awhile ago for concepts as a library to kind of start the discussion around concepts.   There seemed to be some interest around the PR, so I have rebased it and fixed the formatting.
>>
>> Please take a look: https://github.com/D-Programming-Language/phobos/pull/2627
>>
>> -Shammah
>
> For those who are on a sugar-rush from Concepts, maybe this is a fun trick?
>
> It almost works, if only IFTI was smart enough to deal with eponymous identity templates.
>
> ========================================
> int fun(T)(T t) if(is(typeof(T.Put)))
> {
> }
> ========================================
> template Putty(T)
> {
>   static assert(is(typeof(T.Put)));
>
>   alias Putty = T;
> }
> void fun(T)(Putty!T t)
> {
> }
> ========================================

Templates are not bijective, so we'll never be generally able to determine T by matching Putty, i.e. 2 different T could have the same Putty!T type.
Adding an exception for identity templates seems to be a hack.
July 25, 2015
On 26/07/2015 2:14 a.m., Martin Nowak wrote:
> On Saturday, 25 July 2015 at 14:06:05 UTC, Daniel N wrote:
>> On Friday, 24 July 2015 at 19:56:55 UTC, Shammah Chancellor wrote:
>>> I put up a PR for phobos awhile ago for concepts as a library to kind
>>> of start the discussion around concepts.   There seemed to be some
>>> interest around the PR, so I have rebased it and fixed the formatting.
>>>
>>> Please take a look:
>>> https://github.com/D-Programming-Language/phobos/pull/2627
>>>
>>> -Shammah
>>
>> For those who are on a sugar-rush from Concepts, maybe this is a fun
>> trick?
>>
>> It almost works, if only IFTI was smart enough to deal with eponymous
>> identity templates.
>>
>> ========================================
>> int fun(T)(T t) if(is(typeof(T.Put)))
>> {
>> }
>> ========================================
>> template Putty(T)
>> {
>>   static assert(is(typeof(T.Put)));
>>
>>   alias Putty = T;
>> }
>> void fun(T)(Putty!T t)
>> {
>> }
>> ========================================
>
> Templates are not bijective, so we'll never be generally able to
> determine T by matching Putty, i.e. 2 different T could have the same
> Putty!T type.
> Adding an exception for identity templates seems to be a hack.

======================================

template Putty(T)
{
  static assert(is(typeof(T.Put)));

  alias Putty = T;
}
void fun(!T)(Putty!T t)
{
}

=======================================

void fun(__original_T)(__original_T t) if (is(Putty!__original_T == __original_T))
{
}

=======================================

Humm, minor rewrite of source by the front end. Definitely would be doable.
July 25, 2015
On Saturday, 25 July 2015 at 14:14:52 UTC, Martin Nowak wrote:
>
> Templates are not bijective, so we'll never be generally able to determine T by matching Putty, i.e. 2 different T could have the same Putty!T type.
> Adding an exception for identity templates seems to be a hack.

If it only was done for the sake of IFTI, then yes indeed it would be a hack, but probably other things as well such as shorter mangling could benefit from the compiler being aware of identity templates.

July 25, 2015
On Saturday, 25 July 2015 at 13:41:22 UTC, Andrei Alexandrescu wrote:
> Now stack these advantages against the advantages of template constraints. It's a landslide.
>
>
> Andrei

This is a false dichotomy.

July 25, 2015
On 7/25/15 5:24 PM, deadalnix wrote:
> On Saturday, 25 July 2015 at 13:41:22 UTC, Andrei Alexandrescu wrote:
>> Now stack these advantages against the advantages of template
>> constraints. It's a landslide.
>>
>>
>> Andrei
>
> This is a false dichotomy.

We could have both (i.e. add traits to D), but would we want to? -- Andrei
July 25, 2015
On Saturday, 25 July 2015 at 22:09:08 UTC, Andrei Alexandrescu wrote:
> On 7/25/15 5:24 PM, deadalnix wrote:
>> On Saturday, 25 July 2015 at 13:41:22 UTC, Andrei Alexandrescu wrote:
>>> Now stack these advantages against the advantages of template
>>> constraints. It's a landslide.
>>>
>>>
>>> Andrei
>>
>> This is a false dichotomy.
>
> We could have both (i.e. add traits to D), but would we want to? -- Andrei

Yes. Most template code would benefit from it. For the same reason that being able to bypass the type system is important, you also would like that most of the code don't.

« First   ‹ Prev
1 2