Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 25, 2013 wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Hello, I was curious how our fledgling wrap and unwrap routines compare with Go's duck typing - similarities, distinctions, performance. Please share any thoughts, thanks! Andrei |
October 25, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 25 October 2013 at 05:45:53 UTC, Andrei Alexandrescu wrote:
> Hello,
>
> I was curious how our fledgling wrap and unwrap routines compare with Go's duck typing - similarities, distinctions, performance. Please share any thoughts, thanks!
>
> Andrei
Are there some examples somewhere of when using wrap/unwrap is a good design choice? I can imagine it's convenient in some cases, but what's the "killer use".
|
October 26, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 10/25/2013 07:46 AM, Andrei Alexandrescu wrote:
> Hello,
>
> I was curious how our fledgling wrap and unwrap routines compare with
> Go's duck typing - similarities, distinctions, performance. Please share
> any thoughts, thanks!
>
> Andrei
What are you referring to by wrap/unwrap, functions like inputRangeObject?
Martin
|
October 26, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Nowak | On Saturday, 26 October 2013 at 14:39:31 UTC, Martin Nowak wrote: > On 10/25/2013 07:46 AM, Andrei Alexandrescu wrote: >> Hello, >> >> I was curious how our fledgling wrap and unwrap routines compare with >> Go's duck typing - similarities, distinctions, performance. Please share >> any thoughts, thanks! >> >> Andrei > > What are you referring to by wrap/unwrap, functions like inputRangeObject? > > Martin http://dlang.org/phobos-prerelease/std_typecons.html#.wrap http://dlang.org/phobos-prerelease/std_typecons.html#.unwrap |
October 26, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicolas Sicard | For the second example, can you pass x.wrap!(A, B) to functions expecting either A or B? |
October 26, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicolas Sicard | On 10/26/13 7:55 AM, Nicolas Sicard wrote:
> On Saturday, 26 October 2013 at 14:39:31 UTC, Martin Nowak wrote:
>> On 10/25/2013 07:46 AM, Andrei Alexandrescu wrote:
>>> Hello,
>>>
>>> I was curious how our fledgling wrap and unwrap routines compare with
>>> Go's duck typing - similarities, distinctions, performance. Please share
>>> any thoughts, thanks!
>>>
>>> Andrei
>>
>> What are you referring to by wrap/unwrap, functions like
>> inputRangeObject?
>>
>> Martin
>
> http://dlang.org/phobos-prerelease/std_typecons.html#.wrap
> http://dlang.org/phobos-prerelease/std_typecons.html#.unwrap
Yes, sorry for being unclear.
I wonder whether specifying "Go-style wrap/unwrap" would be a fair characterization when announcing 2.064.
Also, is it correct that Linux dynamic library support is really starting with this release? There was some before but not quite usable.
Andrei
|
October 26, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Saturday, 26 October 2013 at 15:08:23 UTC, Andrei Alexandrescu wrote:
> On 10/26/13 7:55 AM, Nicolas Sicard wrote:
>> On Saturday, 26 October 2013 at 14:39:31 UTC, Martin Nowak wrote:
>>> On 10/25/2013 07:46 AM, Andrei Alexandrescu wrote:
>>>> Hello,
>>>>
>>>> I was curious how our fledgling wrap and unwrap routines compare with
>>>> Go's duck typing - similarities, distinctions, performance. Please share
>>>> any thoughts, thanks!
>>>>
>
> I wonder whether specifying "Go-style wrap/unwrap" would be a fair characterization when announcing 2.064.
>
Since Go's "duck typing" is implicit and automatic, and highlighted as such, "Go-style wrap/unwrap" sounds a bit paradoxical... What about "wrap/unwrap for Go-style structural typing"?
Nicolas
|
October 26, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 25 October 2013 at 05:45:53 UTC, Andrei Alexandrescu wrote: > Hello, > > I was curious how our fledgling wrap and unwrap routines compare with Go's duck typing - similarities, distinctions, performance. Please share any thoughts, thanks! > > Andrei This is what I've come up with. It doesn't look like it works with structures? Go doesn't have classes so structures are going to provide the most "Go" like feel. I expect it doesn't work with pseudo members. Go adds methods to a struct similar to C++ friend methods or the UFCS provided by D. Thus, it would feel more natural to a Go programmer to add "friend" functions and expect them to be usable by the typecons.wrap(). And on a D related note: It would be nice to support UFCS during the wrapping, this comes back to the example of arrays. An array is only a range because std.range was imported, if a function checks to see if(isInputRange!R) then arrays would fail if that same module didn't import std.range. If wrap worked with the current scoped "friend" functions, then the caller could easily just arr.wrap!InputRange and move on. This just seems like the main D use-case for this type of feature. I'm also not sure why this code is giving me linker errors. I've gotten the examples to work, but trying to mimic a Go blog isn't working: http://blog.jessta.id.au/2011/06/golang-interfaces.html interface Writer { void Write(string); } void SomeFunction(Writer w){ w.Write("pizza"); } class Human { void Write(string s) { import std.stdio; writeln(s); } } void main() { Human h = new Human();; import std.typecons; SomeFunction(h.wrap!Writer); } undefined reference to `_D3std8typecons24__T4wrapTC5write6WriterZ23__T4wrapTC5write5HumanZ4Impl308__T8mixinAllVAyaa143_6f766572726964652052657475726e5479706521... |
October 27, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2013-10-26 17:09, Andrei Alexandrescu wrote: > Also, is it correct that Linux dynamic library support is really > starting with this release? There was some before but not quite usable. Yes, I think so. In the current release you can statically link with a dynamic library written in D. In the upcoming release dlopen and similar functions should work. There's just a couple of regressions delaying the release. -- /Jacob Carlborg |
October 27, 2013 Re: wrap/unwrap vs Go-style duck typing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Sunday, 27 October 2013 at 10:25:02 UTC, Jacob Carlborg wrote:
> On 2013-10-26 17:09, Andrei Alexandrescu wrote:
>
>> Also, is it correct that Linux dynamic library support is really
>> starting with this release? There was some before but not quite usable.
>
> Yes, I think so. In the current release you can statically link with a dynamic library written in D. In the upcoming release dlopen and similar functions should work.
>
> There's just a couple of regressions delaying the release.
If we want to mention shared library support in the release notes, I think we really ought to make clear (with a big red warning) that D doesn't make any guarantees about ABI stability right now.
David
|
Copyright © 1999-2021 by the D Language Foundation