Re: Interfaces, traits, concepts, and my idea for a DIP

2015-08-01 Thread Piotrek via Digitalmars-d
On Friday, 31 July 2015 at 16:28:30 UTC, jmh530 wrote: Looking at the PR also resolved my earlier question. Running the code as below (do not import std.range) will tell you exactly what isn't implemented from isInputRange (in this case, I commented out popFront). Very cool. template

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-31 Thread Atila Neves via Digitalmars-d
On Friday, 31 July 2015 at 11:16:48 UTC, Biotronic wrote: On Thursday, 30 July 2015 at 10:40:59 UTC, Atila Neves wrote: There's still the problem of having two names for each constraint: checkInputRange and isInputRange. But... we could also establish the convention of checkXXX and use string

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-31 Thread Atila Neves via Digitalmars-d
On Friday, 31 July 2015 at 14:23:28 UTC, Atila Neves wrote: On Friday, 31 July 2015 at 11:16:48 UTC, Biotronic wrote: On Thursday, 30 July 2015 at 10:40:59 UTC, Atila Neves wrote: [...] Why are there two different things in the first place? @satisfies!(myConcept, T) should test the

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-31 Thread Atila Neves via Digitalmars-d
On Thursday, 30 July 2015 at 19:12:27 UTC, jmh530 wrote: On Thursday, 30 July 2015 at 10:40:59 UTC, Atila Neves wrote: [...] I might be overthinking this. You would still need to define something for checkInputRange. Are you thinking something simple like template checkInputRange(R) {

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-31 Thread Sebastiaan Koppe via Digitalmars-d
On Friday, 31 July 2015 at 14:23:28 UTC, Atila Neves wrote: On Friday, 31 July 2015 at 11:16:48 UTC, Biotronic wrote: Why can't another template use the very same concept information to check if a type implements the concept? e.g.: @satisfies!(myConcept, MyStruct) struct MyStruct { /* ... */

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-31 Thread jmh530 via Digitalmars-d
On Friday, 31 July 2015 at 14:24:58 UTC, Atila Neves wrote: Notice however, that (again, in the PR), the real definition happens only once, in the check function. Then the constraint is always a trivial `enum MyConstraint = is(typeof(myCheckFunction));`. It's just a matter of moving the

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-31 Thread Biotronic via Digitalmars-d
On Thursday, 30 July 2015 at 10:40:59 UTC, Atila Neves wrote: There's still the problem of having two names for each constraint: checkInputRange and isInputRange. But... we could also establish the convention of checkXXX and use string mixins to turn this: @satifies!(isInputRange, MyRange)

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-31 Thread cym13 via Digitalmars-d
On Friday, 31 July 2015 at 11:16:48 UTC, Biotronic wrote: Why are there two different things in the first place? @satisfies!(myConcept, T) should test the constraints and give a sensible error message. This you use to indicate that type T implements myConcept. Why can't another template use

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-31 Thread cym13 via Digitalmars-d
On Thursday, 30 July 2015 at 10:40:59 UTC, Atila Neves wrote: On Wednesday, 29 July 2015 at 20:41:02 UTC, Tofu Ninja wrote: On Wednesday, 29 July 2015 at 20:26:53 UTC, Tofu Ninja wrote: If you write: @satisfies!(isInputRange, MyRange) struct MyRange { ... } the UDA can check it self, it

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-30 Thread Sean Campbell via Digitalmars-d
On Tuesday, 28 July 2015 at 18:23:02 UTC, Tofu Ninja wrote: On Tuesday, 28 July 2015 at 13:23:37 UTC, Daniel Kozák wrote: [...] I have actually thought about this as well, and a thing that could actually make this possible is if UDAs could get the thing they are attached to. I realized it

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-30 Thread jmh530 via Digitalmars-d
On Thursday, 30 July 2015 at 10:40:59 UTC, Atila Neves wrote: You still wouldn't get a better error message here than with: struct MyRange { ... static assert(isInputRange!MyRange); } It's less typing, but you still wouldn't know why the static assertion failed. Now, if we make

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-30 Thread Atila Neves via Digitalmars-d
On Wednesday, 29 July 2015 at 20:41:02 UTC, Tofu Ninja wrote: On Wednesday, 29 July 2015 at 20:26:53 UTC, Tofu Ninja wrote: If you write: @satisfies!(isInputRange, MyRange) struct MyRange { ... } the UDA can check it self, it really works as expected. Which is why I suggested a way to get

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-29 Thread Atila Neves via Digitalmars-d
On Tuesday, 28 July 2015 at 12:49:17 UTC, Atila Neves wrote: So I missed the boat on the lengthy Rust traits discussion on the other thread. I confess I didn't have time to read all of it so forgive me if I bring up something that's already been said there. [...] I went back to my copy of

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-29 Thread Andrei Alexandrescu via Digitalmars-d
On 7/29/15 4:25 AM, Roland Hadinger wrote: @satisfies(isInputRange) struct MyRange { ... } This is straight from the creative use of what we have mantra that I think is worth exploring. -- Andrei

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-29 Thread Tofu Ninja via Digitalmars-d
On Wednesday, 29 July 2015 at 20:26:53 UTC, Tofu Ninja wrote: If you write: @satisfies!(isInputRange, MyRange) struct MyRange { ... } the UDA can check it self, it really works as expected. Which is why I suggested a way to get whatever the UDA is attached to automatically in my other post.

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-29 Thread Tofu Ninja via Digitalmars-d
On Wednesday, 29 July 2015 at 14:51:52 UTC, Atila Neves wrote: On Wednesday, 29 July 2015 at 08:25:04 UTC, Roland Hadinger wrote: On Tuesday, 28 July 2015 at 12:49:17 UTC, Atila Neves wrote: So... instead of having traits / concepts, what I wanted from D is to be able to do this: struct

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-29 Thread Roland Hadinger via Digitalmars-d
On Tuesday, 28 July 2015 at 12:49:17 UTC, Atila Neves wrote: So... instead of having traits / concepts, what I wanted from D is to be able to do this: struct MyRange: isInputRange { ... } +1 or struct MyRange: static isInputRange { ... } // that way classes could do this too What about

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-29 Thread Kagamin via Digitalmars-d
On Tuesday, 28 July 2015 at 13:10:43 UTC, Atila Neves wrote: I guess, but not easily. I've written template mixins to do that before and it was awkward. What was awkward?

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-29 Thread Atila Neves via Digitalmars-d
On Wednesday, 29 July 2015 at 06:05:37 UTC, Kagamin wrote: On Tuesday, 28 July 2015 at 13:10:43 UTC, Atila Neves wrote: I guess, but not easily. I've written template mixins to do that before and it was awkward. What was awkward? Writing a generic solution that would work for multiple

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-29 Thread Atila Neves via Digitalmars-d
On Wednesday, 29 July 2015 at 08:25:04 UTC, Roland Hadinger wrote: On Tuesday, 28 July 2015 at 12:49:17 UTC, Atila Neves wrote: So... instead of having traits / concepts, what I wanted from D is to be able to do this: struct MyRange: isInputRange { ... } +1 or struct MyRange: static

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-28 Thread ChangLong via Digitalmars-d
On Tuesday, 28 July 2015 at 12:49:17 UTC, Atila Neves wrote: So... instead of having traits / concepts, what I wanted from D is to be able to do this: struct MyRange: isInputRange { ... } or struct MyRange: static isInputRange { ... } // that way classes could do this too +1 Concept

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-28 Thread jmh530 via Digitalmars-d
On Tuesday, 28 July 2015 at 13:23:37 UTC, Daniel Kozák wrote: I would use something like this: @interface(InputRange, ...) struct MyRange { ... } @interface(InputRange, ...) class MyClassRange { ... } I get the change from isInputRange to InputRange, because isInputRange is like a

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-28 Thread Daniel Kozák via Digitalmars-d
On Tue, 28 Jul 2015 12:49:15 + Atila Neves atila.ne...@gmail.com wrote: So I missed the boat on the lengthy Rust traits discussion on the other thread. I confess I didn't have time to read all of it so forgive me if I bring up something that's already been said there. Since last

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-28 Thread Atila Neves via Digitalmars-d
On Tuesday, 28 July 2015 at 13:02:06 UTC, Jack Stouffer wrote: Overall a great idea! On Tuesday, 28 July 2015 at 12:49:17 UTC, Atila Neves wrote: struct MyRange: static isInputRange { ... } I don't think you even need new syntax to get the error messages. If you have a static assert in your

Interfaces, traits, concepts, and my idea for a DIP

2015-07-28 Thread Atila Neves via Digitalmars-d
So I missed the boat on the lengthy Rust traits discussion on the other thread. I confess I didn't have time to read all of it so forgive me if I bring up something that's already been said there. Since last year, after having written a ton of generic code with compile-time reflection and

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-28 Thread Jack Stouffer via Digitalmars-d
Overall a great idea! On Tuesday, 28 July 2015 at 12:49:17 UTC, Atila Neves wrote: struct MyRange: static isInputRange { ... } I don't think you even need new syntax to get the error messages. If you have a static assert in your unit tests for isInputRange!MyType, then theoretically you

Re: Interfaces, traits, concepts, and my idea for a DIP

2015-07-28 Thread Tofu Ninja via Digitalmars-d
On Tuesday, 28 July 2015 at 13:23:37 UTC, Daniel Kozák wrote: I was thinking about same many times before. With one difference: instead of this: struct MyRange: isInputRange { ... } I would use something like this: @interface(InputRange, ...) struct MyRange { ... } @interface(InputRange,