November 21, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shammah Chancellor | On 2013-11-21 00:27, Shammah Chancellor wrote: > I just watched this talk from the goto conference by Walter Bright > (https://www.youtube.com/watch?v=cQkBOCo8UrE) and he makes reference to > "concepts." However, they look almost identical to Protocols in > Smalltalk -- something which I would very much like to see in D. > > It basically works much like an interface, but instead of declaring it, > you check the type to see if it defines the appropriate methods. > > In fact -- I believe this could be implemented today with __traits and > static foreach to simply check to see if a type conforms to a protocol > at compile time. > > implementsProtocol!( R, InputRange!(int) ); > > where InputRange!() could just be a templated interface. > > Having this in phobos would be really helpful! If there is interest in > this, I'll write a template up and submit it to phobos. D you mean something like this: http://forum.dlang.org/thread/l6jgha$1elj$1@digitalmars.com#post-l6kdvj:2428tr:241:40digitalmars.com I would like to have that. -- /Jacob Carlborg |
November 21, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Thursday, 21 November 2013 at 07:50:11 UTC, Jacob Carlborg wrote:
> I guess his suggestion would be something like this:
>
> interface InputRange (R)
> {
> @property bool empty ();
> void popFront ();
> ElementType!(R) front ();
> }
>
> void foo (R) (R r) if(implements!(InputRange!(R)))
>
> Personally I think it's nice to have a concrete type like this.
I perfectly understand his suggestion as I have implemented it already few times ;) Again - it is nice, but does not give you any real advantage unless can also be used with `wrap`.
|
November 21, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 11/20/13 11:50 PM, Jacob Carlborg wrote:
> I guess his suggestion would be something like this:
>
> interface InputRange (R)
> {
> @property bool empty ();
> void popFront ();
> ElementType!(R) front ();
> }
>
> void foo (R) (R r) if(implements!(InputRange!(R)))
Interfaces can't check for a variety of things that Boolean conditions can (isInfinite comes to mind).
Andrei
|
November 21, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shammah Chancellor | > > Having this in phobos would be really helpful! If there is interest in this, I'll write a template up and submit it to phobos. > > -Shammah Why not simply make your own repo somewhere (Gitorious, GitHub, Savannah, etc) and once you are done just announce it at here so we can try it? Or, alternatively, write a DIP for it (http://wiki.dlang.org). |
November 21, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2013-11-21 17:02, Andrei Alexandrescu wrote: > Interfaces can't check for a variety of things that Boolean conditions > can (isInfinite comes to mind). Why wouldn't you be able to put the implementation of isInfinite in an interface? I might no be any advantage over a template like it is now, but it should be possible. One advantage interfaces have is that they support inheritance. It's easy to see which other properties are supported. Not as easy to see that isInfinite "inherits" from isInputRange. -- /Jacob Carlborg |
November 21, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 11/21/13 10:45 AM, Jacob Carlborg wrote:
> On 2013-11-21 17:02, Andrei Alexandrescu wrote:
>
>> Interfaces can't check for a variety of things that Boolean conditions
>> can (isInfinite comes to mind).
>
> Why wouldn't you be able to put the implementation of isInfinite in an
> interface?
It's a value, not a type.
Walter and I went a couple of times over the idea of using interfaces for concept conformance during the early days, and figured general Boolean logic is more powerful for expressing constraints.
Andrei
|
November 22, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2013-11-21 19:30:00 +0000, Andrei Alexandrescu said:
> On 11/21/13 10:45 AM, Jacob Carlborg wrote:
>> On 2013-11-21 17:02, Andrei Alexandrescu wrote:
>>
>>> Interfaces can't check for a variety of things that Boolean conditions
>>> can (isInfinite comes to mind).
>>
>> Why wouldn't you be able to put the implementation of isInfinite in an
>> interface?
>
> It's a value, not a type.
>
> Walter and I went a couple of times over the idea of using interfaces for concept conformance during the early days, and figured general Boolean logic is more powerful for expressing constraints.
>
>
> Andrei
I am not suggesting using polymorphism for this. That would to the same diamond problems when things support multiple concepts. All I am suggesting is that Phobos should have a a generalized checker for concepts rather than a bunch of specific templates. And I am suggesting that templated interfaces could be the thing this checks against (or other concrete types as needed)
-Shammah
|
November 22, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dejan Lekic | On 2013-11-21 16:13:31 +0000, Dejan Lekic said:
>>
>>
>> Having this in phobos would be really helpful! If there is interest in this, I'll write a template up and submit it to phobos.
>>
>> -Shammah
>
> Why not simply make your own repo somewhere (Gitorious, GitHub, Savannah, etc) and once you are done just announce it at here so we can try it? Or, alternatively, write a DIP for it (http://wiki.dlang.org).
Because I currently do not use concepts explicitely anywhere in my Code.. I watched the talk and thought it was an awesome idea. I'm not going to invest the effort for something I am not currently using if everyone else thinks the idea is not useful enough to be part of the standard library. If and when I need to start using concepts more, I would implement a generic template for it, rather than the explicite one.
Additionally, I left active participation in the D community about five years ago due to life circumstances -- and only recently rejoined. I am not familiar with the DIP procedures.
-Shammah
|
November 22, 2013 Re: Protocols vs Concepts? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shammah Chancellor | On 2013-11-22 01:17, Shammah Chancellor wrote: > Additionally, I left active participation in the D community about five > years ago due to life circumstances -- and only recently rejoined. I am > not familiar with the DIP procedures. DIP - D Improvement Proposal. Just look at the other ones to get a feel for the structure. Then post here if you decide to write one. http://wiki.dlang.org/DIPs -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation