This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Anything equivalent to C#'s `dynamic`?

21 replies
Yang Zhang
Joined: 2010-02-09,
User offline. Last seen 42 years 45 weeks ago.
I believe the answer is no, but wouldn't hurt to check: anything in Scala that's equivalent to C#'s `dynamic` keyword? Anything on the horizon?

I know about scala.Dynamic, which is not the same thing - in C# you don't know the types at compile time, and the dynamic type propagates.
I also know about invokedynamic, which is not the same thing - invokedynamic is the infrastructure that would make language constructs like `dynamic` performant.
Anything on the horizon?
http://msdn.microsoft.com/en-us/library/dd264736.aspx
John Nilsson
Joined: 2008-12-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Anything equivalent to C#'s `dynamic`?

Maybe there is less need given structural types, terser syntax and in general a more advanced type system. Do you have an example usecase?

Mvh,
John

Sent from my phone

Den 19 jul 2011 06:50 skrev "Yang Zhang" <yanghatespam [at] gmail [dot] com>:
> I believe the answer is no, but wouldn't hurt to check: anything in Scala
> that's equivalent to C#'s `dynamic` keyword? Anything on the horizon?
>
> I know about scala.Dynamic, which is not the same thing - in C# you don't
> know the types at compile time, and the dynamic type propagates.
>
> I also know about invokedynamic, which is not the same thing - invokedynamic
> is the infrastructure that would make language constructs like `dynamic`
> performant.
>
> Anything on the horizon?
>
> http://msdn.microsoft.com/en-us/library/dd264736.aspx
Yang Zhang
Joined: 2010-02-09,
User offline. Last seen 42 years 45 weeks ago.
Re: Anything equivalent to C#'s `dynamic`?

Sorry, not interested in motivating/debating this, but maybe someone
else can chime in

On Tue, Jul 19, 2011 at 4:47 AM, John Nilsson wrote:
> Maybe there is less need given structural types, terser syntax and in
> general a more advanced type system. Do you have an example usecase?
>
> Mvh,
> John
>
> Sent from my phone
>
> Den 19 jul 2011 06:50 skrev "Yang Zhang" :
>> I believe the answer is no, but wouldn't hurt to check: anything in Scala
>> that's equivalent to C#'s `dynamic` keyword? Anything on the horizon?
>>
>> I know about scala.Dynamic, which is not the same thing - in C# you don't
>> know the types at compile time, and the dynamic type propagates.
>>
>> I also know about invokedynamic, which is not the same thing -
>> invokedynamic
>> is the infrastructure that would make language constructs like `dynamic`
>> performant.
>>
>> Anything on the horizon?
>>
>> http://msdn.microsoft.com/en-us/library/dd264736.aspx
>

Chris Twiner
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Anything equivalent to C#'s `dynamic`?

sorry but if you are asking such a question you've really got no right
not to provide a usecase.

On Tue, Jul 19, 2011 at 8:32 PM, Yang Zhang wrote:
> Sorry, not interested in motivating/debating this, but maybe someone
> else can chime in
>
> On Tue, Jul 19, 2011 at 4:47 AM, John Nilsson wrote:
>> Maybe there is less need given structural types, terser syntax and in
>> general a more advanced type system. Do you have an example usecase?
>>
>> Mvh,
>> John
>>
>> Sent from my phone
>>
>> Den 19 jul 2011 06:50 skrev "Yang Zhang" :
>>> I believe the answer is no, but wouldn't hurt to check: anything in Scala
>>> that's equivalent to C#'s `dynamic` keyword? Anything on the horizon?
>>>
>>> I know about scala.Dynamic, which is not the same thing - in C# you don't
>>> know the types at compile time, and the dynamic type propagates.
>>>
>>> I also know about invokedynamic, which is not the same thing -
>>> invokedynamic
>>> is the infrastructure that would make language constructs like `dynamic`
>>> performant.
>>>
>>> Anything on the horizon?
>>>
>>> http://msdn.microsoft.com/en-us/library/dd264736.aspx
>>
>
>
>
> --
> Yang Zhang
> http://yz.mit.edu/
>

John Nilsson
Joined: 2008-12-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Anything equivalent to C#'s `dynamic`?
Ok, lets try this then:

I fail to see how the properties of scala.Dynamic is not a superset of the C# dynamic keyword. Granted my undestanding of both is based on a quick googling just now. From what I can see the code in http://pastie.org/1469174 completley implements the C# dynamic semantics.

Could you then supply an example illustrating a use of C# dynamic that is not supported by scala.Dynamic?

BR,
John

On Tue, Jul 19, 2011 at 8:32 PM, Yang Zhang <yanghatespam [at] gmail [dot] com> wrote:
Sorry, not interested in motivating/debating this, but maybe someone
else can chime in

On Tue, Jul 19, 2011 at 4:47 AM, John Nilsson <john [at] milsson [dot] nu> wrote:
> Maybe there is less need given structural types, terser syntax and in
> general a more advanced type system. Do you have an example usecase?
>
> Mvh,
> John
>
> Sent from my phone
>
> Den 19 jul 2011 06:50 skrev "Yang Zhang" <yanghatespam [at] gmail [dot] com>:
>> I believe the answer is no, but wouldn't hurt to check: anything in Scala
>> that's equivalent to C#'s `dynamic` keyword? Anything on the horizon?
>>
>> I know about scala.Dynamic, which is not the same thing - in C# you don't
>> know the types at compile time, and the dynamic type propagates.
>>
>> I also know about invokedynamic, which is not the same thing -
>> invokedynamic
>> is the infrastructure that would make language constructs like `dynamic`
>> performant.
>>
>> Anything on the horizon?
>>
>> http://msdn.microsoft.com/en-us/library/dd264736.aspx
>



--
Yang Zhang
http://yz.mit.edu/

Chris Twiner
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Anything equivalent to C#'s `dynamic`?

Hi All,

Jim has just sent me an email off list showing that my emails tone and
content is off.

To the tone, appologies, to the content - I mean only to criticise the
reply to John's email not the original request.

Thanks to Jim for caring enough to let me know.

Cheers,
Chris

On Tue, Jul 19, 2011 at 8:46 PM, Chris Twiner wrote:
> sorry but if you are asking such a question you've really got no right
> not to provide a usecase.
>
> On Tue, Jul 19, 2011 at 8:32 PM, Yang Zhang wrote:
>> Sorry, not interested in motivating/debating this, but maybe someone
>> else can chime in
>>
>> On Tue, Jul 19, 2011 at 4:47 AM, John Nilsson wrote:
>>> Maybe there is less need given structural types, terser syntax and in
>>> general a more advanced type system. Do you have an example usecase?
>>>
>>> Mvh,
>>> John
>>>
>>> Sent from my phone
>>>
>>> Den 19 jul 2011 06:50 skrev "Yang Zhang" :
>>>> I believe the answer is no, but wouldn't hurt to check: anything in Scala
>>>> that's equivalent to C#'s `dynamic` keyword? Anything on the horizon?
>>>>
>>>> I know about scala.Dynamic, which is not the same thing - in C# you don't
>>>> know the types at compile time, and the dynamic type propagates.
>>>>
>>>> I also know about invokedynamic, which is not the same thing -
>>>> invokedynamic
>>>> is the infrastructure that would make language constructs like `dynamic`
>>>> performant.
>>>>
>>>> Anything on the horizon?
>>>>
>>>> http://msdn.microsoft.com/en-us/library/dd264736.aspx
>>>
>>
>>
>>
>> --
>> Yang Zhang
>> http://yz.mit.edu/
>>
>

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Anything equivalent to C#'s `dynamic`?

On Monday 18 July 2011, Yang Zhang wrote:
> I believe the answer is no, but wouldn't hurt to check: anything in
> Scala that's equivalent to C#'s `dynamic` keyword? Anything on the
> horizon?
> ...

Please explain what it is.

Randall Schulz

kaja47
Joined: 2011-07-23,
User offline. Last seen 42 years 45 weeks ago.
Re: Anything equivalent to C#'s `dynamic`?

Dne Sat, 23 Jul 2011 04:39:31 +0200 Randall R Schulz
napsal(a):

> On Monday 18 July 2011, Yang Zhang wrote:
>> I believe the answer is no, but wouldn't hurt to check: anything in
>> Scala that's equivalent to C#'s `dynamic` keyword? Anything on the
>> horizon?
>> ...
>
> Please explain what it is.
>
>
> Randall Schulz

There is trait Dynamic.
http://www.scala-lang.org/api/current/index.html#scala.Dynamic
It isn't exactly the same as C# dynamic, but you can do very similar stuff
with that.

K.

Andrew Garman
Joined: 2011-07-13,
User offline. Last seen 42 years 45 weeks ago.
Re: Anything equivalent to C#'s `dynamic`?

In C# instead of writing:

var foo = ...
foo.invoke("function1" ...)

You can write:

dynamic foo = ...
foo.function1(...)

Aside from the sugar there is a dynamic dispatch runtime in the .NET
runtime that optimizes the dynamic calls.

On Jul 22, 10:39 pm, Randall R Schulz wrote:
> On Monday 18 July 2011, Yang Zhang wrote:
>
> > I believe the answer is no, but wouldn't hurt to check: anything in
> > Scala that's equivalent to C#'s `dynamic` keyword? Anything on the
> > horizon?
> > ...
>
> Please explain what it is.
>
> Randall Schulz

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Re: Anything equivalent to C#'s `dynamic`?


On Sat, Jul 23, 2011 at 1:41 PM, Andrew Garman <andru [dot] garman [at] gmail [dot] com> wrote:
In C# instead of writing:

var foo = ...
foo.invoke("function1" ...)

You can write:

dynamic foo = ...
foo.function1(...)

Aside from the sugar there is a dynamic dispatch runtime in the .NET
runtime that optimizes the dynamic calls.

Yes, that's precisly what Scala's Dynamic type will also achieve. And JDK 1.7 contributes the invokedynamic instruction to make it fast. I should note that in Scala 2.9, Dynamic is only enabled with -Xexperimental, but it will be a standard feature in Scala 2.10.

 -- Martin

soc
Joined: 2010-02-07,
User offline. Last seen 34 weeks 5 days ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

Hi,
> Yes, that's precisly what Scala's Dynamic type will also achieve. And
> JDK 1.7 contributes the invokedynamic instruction to make it fast. I
> should note that in Scala 2.9, Dynamic is only enabled with
> -Xexperimental, but it will be a standard feature in Scala 2.10.

Does that mean Scala will get different branches to incooperate newer
features? (Thinking about the better support for "control flow
exceptions" in java.lang.Throwable ...

I just remembered that the JVM language summit was held in the last few
days. I wonder what's the reason no one from Scala attended? (No attack,
just seriously interested.)

Thanks and bye,

Simon

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Re: Anything equivalent to C#'s `dynamic`?


On Sat, Jul 23, 2011 at 2:07 PM, Simon Ochsenreither <simon [at] ochsenreither [dot] de> wrote:
Hi,
Yes, that's precisly what Scala's Dynamic type will also achieve. And JDK 1.7 contributes the invokedynamic instruction to make it fast. I should note that in Scala 2.9, Dynamic is only enabled with -Xexperimental, but it will be a standard feature in Scala 2.10.

Does that mean Scala will get different branches to incooperate newer features? (Thinking about the better support for "control flow exceptions" in java.lang.Throwable ...

I just remembered that the JVM language summit was held in the last few days. I wonder what's the reason no one from Scala attended? (No attack, just seriously interested.)

Paul Phillips did attend.  Besides, we were all very busy with other conferences over the last weeks: Scala Days, Scala eXchange, GOTO, Salathon, now OSCON Java where I have a keynote and two talks. I am also going to attend the JVM language summit at OSCON tomorrow.

Cheers

 -- Martin


soc
Joined: 2010-02-07,
User offline. Last seen 34 weeks 5 days ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

Hi,
> Paul Phillips did attend.
Cool, didn't knew that.

> Besides, we were all very busy with other conferences over the last
> weeks: Scala Days, Scala eXchange, GOTO, Salathon, now OSCON Java
> where I have a keynote and two talks. I am also going to attend the
> JVM language summit at OSCON tomorrow.

Ok, thanks! So only time constraints and nothing political or otherwise
troubling...

If Dynamic will be first available in June 2012 (without compiler flag),
will there be other, smaller features introduced into the 2.9.x series?
Will those improvements be based on 2.9.0.1 or on the ongoing trunk?

Thanks and bye!

Simon

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

On Saturday 23 July 2011, Simon Ochsenreither wrote:
> Hi,
>
> > Paul Phillips did attend.
>
> Cool, didn't knew that.
>
> > Besides, we were all very busy with other conferences over the last
> > weeks: Scala Days, Scala eXchange, GOTO, Salathon, now OSCON Java
> > where I have a keynote and two talks. I am also going to attend the
> > JVM language summit at OSCON tomorrow.
>
> Ok, thanks! So only time constraints and nothing political or
> otherwise troubling...
>
> If Dynamic will be first available in June 2012 (without compiler
> flag), will there be other, smaller features introduced into the
> 2.9.x series? Will those improvements be based on 2.9.0.1 or on the
> ongoing trunk?
>
> Thanks and bye!
>
> Simon

I really need a release that includes the fix for SI-4593 [1].

Randall Schulz

[1] https://issues.scala-lang.org/browse/SI-4593

Yang Zhang
Joined: 2010-02-09,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

On Sat, Jul 23, 2011 at 5:02 AM, martin odersky wrote:
>
>
> On Sat, Jul 23, 2011 at 1:41 PM, Andrew Garman
> wrote:
>>
>> In C# instead of writing:
>>
>> var foo = ...
>> foo.invoke("function1" ...)
>>
>> You can write:
>>
>> dynamic foo = ...
>> foo.function1(...)
>>
>> Aside from the sugar there is a dynamic dispatch runtime in the .NET
>> runtime that optimizes the dynamic calls.
>>
> Yes, that's precisly what Scala's Dynamic type will also achieve. And JDK
> 1.7 contributes the invokedynamic instruction to make it fast. I should note
> that in Scala 2.9, Dynamic is only enabled with -Xexperimental, but it will
> be a standard feature in Scala 2.10.

Correct me if I'm wrong, but Dynamic appears to be quite different
from C# dynamic. As Daniel Spiewak points out in
https://groups.google.com/forum/#!msg/scala-language/k2RZEOOy_O4/ScVRU5p_TogJ,
Dynamic basically just gives you missing method interception. Contrast
this with the overview of C# dynamic here:
http://msdn.microsoft.com/en-us/library/dd264736.aspx.

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

On Sun, Jul 24, 2011 at 00:46, Yang Zhang wrote:
>
> Correct me if I'm wrong, but Dynamic appears to be quite different
> from C# dynamic. As Daniel Spiewak points out in

It is different.

> https://groups.google.com/forum/#!msg/scala-language/k2RZEOOy_O4/ScVRU5p_TogJ,
> Dynamic basically just gives you missing method interception. Contrast
> this with the overview of C# dynamic here:
> http://msdn.microsoft.com/en-us/library/dd264736.aspx.

Huh, what? C#'s dynamic just gives you an automatic method forwarding
without type checking. Dynamic gives you the basic tools that let you
do that or all sort of other things. For example, you could have the
Dynamic proxy look up a naming service for a provider of the method it
received, and then forward that request to that.

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 3 days ago.
Re: Re: Anything equivalent to C#'s `dynamic`?
Yang,
Scala's Dynamic trait gives you the tools to roll-your-own implementation of C#'s Dynamic. Look at the pastie John linked to, or this one, which has the same example and another involving XML: https://gist.github.com/783394
How does this not implement the semantics of C#'s Dynamic?
--j
On Sat, Jul 23, 2011 at 11:46 PM, Yang Zhang <yanghatespam [at] gmail [dot] com> wrote:
On Sat, Jul 23, 2011 at 5:02 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
>
>
> On Sat, Jul 23, 2011 at 1:41 PM, Andrew Garman <andru [dot] garman [at] gmail [dot] com>
> wrote:
>>
>> In C# instead of writing:
>>
>> var foo = ...
>> foo.invoke("function1" ...)
>>
>> You can write:
>>
>> dynamic foo = ...
>> foo.function1(...)
>>
>> Aside from the sugar there is a dynamic dispatch runtime in the .NET
>> runtime that optimizes the dynamic calls.
>>
> Yes, that's precisly what Scala's Dynamic type will also achieve. And JDK
> 1.7 contributes the invokedynamic instruction to make it fast. I should note
> that in Scala 2.9, Dynamic is only enabled with -Xexperimental, but it will
> be a standard feature in Scala 2.10.

Correct me if I'm wrong, but Dynamic appears to be quite different
from C# dynamic. As Daniel Spiewak points out in
https://groups.google.com/forum/#!msg/scala-language/k2RZEOOy_O4/ScVRU5p_TogJ,
Dynamic basically just gives you missing method interception. Contrast
this with the overview of C# dynamic here:
http://msdn.microsoft.com/en-us/library/dd264736.aspx.

--
Yang Zhang
http://yz.mit.edu/

Yang Zhang
Joined: 2010-02-09,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

Yeah, sorry, should have been more specific - I was thinking C# was a
bit more than dynamic method dispatch. For instance, you can do the
following with C# dynamic, but not DynamicImpl:

dynamic x = 5
x = x / 2

But for that you can just try to add in all possible primitive
operations as special cases. More generally, though, whereas C#
dynamic seems to capture the "full expressiveness" of C#, doesn't seem
like there's anything here that can capture the equivalent "full
expressiveness" of Scala, e.g. run-time implicit conversion
resolution. But that's just one extreme in the spectrum of
possibilities.

BTW, how would you optimize DynamicImpl with invokedynamic?

Also, again, no real motivations nor expectations here - just asking
out of curiosity/to learn, not to debate.

On Sun, Jul 24, 2011 at 5:52 PM, Jorge Ortiz wrote:
> Yang,
> Scala's Dynamic trait gives you the tools to roll-your-own implementation of
> C#'s Dynamic. Look at the pastie John linked to, or this one, which has the
> same example and another involving XML: https://gist.github.com/783394
> How does this not implement the semantics of C#'s Dynamic?
> --j
> On Sat, Jul 23, 2011 at 11:46 PM, Yang Zhang wrote:
>>
>> On Sat, Jul 23, 2011 at 5:02 AM, martin odersky
>> wrote:
>> >
>> >
>> > On Sat, Jul 23, 2011 at 1:41 PM, Andrew Garman
>> > wrote:
>> >>
>> >> In C# instead of writing:
>> >>
>> >> var foo = ...
>> >> foo.invoke("function1" ...)
>> >>
>> >> You can write:
>> >>
>> >> dynamic foo = ...
>> >> foo.function1(...)
>> >>
>> >> Aside from the sugar there is a dynamic dispatch runtime in the .NET
>> >> runtime that optimizes the dynamic calls.
>> >>
>> > Yes, that's precisly what Scala's Dynamic type will also achieve. And
>> > JDK
>> > 1.7 contributes the invokedynamic instruction to make it fast. I should
>> > note
>> > that in Scala 2.9, Dynamic is only enabled with -Xexperimental, but it
>> > will
>> > be a standard feature in Scala 2.10.
>>
>> Correct me if I'm wrong, but Dynamic appears to be quite different
>> from C# dynamic. As Daniel Spiewak points out in
>>
>> https://groups.google.com/forum/#!msg/scala-language/k2RZEOOy_O4/ScVRU5p_TogJ,
>> Dynamic basically just gives you missing method interception. Contrast
>> this with the overview of C# dynamic here:
>> http://msdn.microsoft.com/en-us/library/dd264736.aspx.
>>
>> --
>> Yang Zhang
>> http://yz.mit.edu/
>
>

Ismael Juma 2
Joined: 2011-01-22,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

On Sat, Jul 23, 2011 at 1:07 PM, Simon Ochsenreither
wrote:
> Does that mean Scala will get different branches to incooperate newer
> features? (Thinking about the better support for "control flow exceptions"
> in java.lang.Throwable ...

I also wondered about that when I was reading the slides for the
presentation given by Brian Goetz in the JVM Summit:

"Code generation strategy for lambdas"
http://www.wiki.jvmlangsummit.com/images/1/1e/2011_Goetz_Lambda.pdf

It seems like Scala's strategy could be improved by taking advantage
of invokedynamic.

Best,
Ismael

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 3 days ago.
Re: Re: Anything equivalent to C#'s `dynamic`?
Yeah, the code I pasted is a toy implementation I banged out in 15minutes when Dynamic first came out. It breaks in several ways around primitives, but a production-ready implementation would take these things into account.
Does C#'s Dynamic work even with extension methods? That's interesting. I bet with a native Scala reflection library, you could mimic the rules for implicit resolution and have implicits work too.

--j
On Mon, Jul 25, 2011 at 3:46 AM, Yang Zhang <yanghatespam [at] gmail [dot] com> wrote:
Yeah, sorry, should have been more specific - I was thinking C# was a
bit more than dynamic method dispatch. For instance, you can do the
following with C# dynamic, but not DynamicImpl:

dynamic x = 5
x = x / 2

But for that you can just try to add in all possible primitive
operations as special cases. More generally, though, whereas C#
dynamic seems to capture the "full expressiveness" of C#, doesn't seem
like there's anything here that can capture the equivalent "full
expressiveness" of Scala, e.g. run-time implicit conversion
resolution. But that's just one extreme in the spectrum of
possibilities.

BTW, how would you optimize DynamicImpl with invokedynamic?

Also, again, no real motivations nor expectations here - just asking
out of curiosity/to learn, not to debate.

On Sun, Jul 24, 2011 at 5:52 PM, Jorge Ortiz <jorge [dot] ortiz [at] gmail [dot] com> wrote:
> Yang,
> Scala's Dynamic trait gives you the tools to roll-your-own implementation of
> C#'s Dynamic. Look at the pastie John linked to, or this one, which has the
> same example and another involving XML: https://gist.github.com/783394
> How does this not implement the semantics of C#'s Dynamic?
> --j
> On Sat, Jul 23, 2011 at 11:46 PM, Yang Zhang <yanghatespam [at] gmail [dot] com> wrote:
>>
>> On Sat, Jul 23, 2011 at 5:02 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch>
>> wrote:
>> >
>> >
>> > On Sat, Jul 23, 2011 at 1:41 PM, Andrew Garman <andru [dot] garman [at] gmail [dot] com>
>> > wrote:
>> >>
>> >> In C# instead of writing:
>> >>
>> >> var foo = ...
>> >> foo.invoke("function1" ...)
>> >>
>> >> You can write:
>> >>
>> >> dynamic foo = ...
>> >> foo.function1(...)
>> >>
>> >> Aside from the sugar there is a dynamic dispatch runtime in the .NET
>> >> runtime that optimizes the dynamic calls.
>> >>
>> > Yes, that's precisly what Scala's Dynamic type will also achieve. And
>> > JDK
>> > 1.7 contributes the invokedynamic instruction to make it fast. I should
>> > note
>> > that in Scala 2.9, Dynamic is only enabled with -Xexperimental, but it
>> > will
>> > be a standard feature in Scala 2.10.
>>
>> Correct me if I'm wrong, but Dynamic appears to be quite different
>> from C# dynamic. As Daniel Spiewak points out in
>>
>> https://groups.google.com/forum/#!msg/scala-language/k2RZEOOy_O4/ScVRU5p_TogJ,
>> Dynamic basically just gives you missing method interception. Contrast
>> this with the overview of C# dynamic here:
>> http://msdn.microsoft.com/en-us/library/dd264736.aspx.
>>
>> --
>> Yang Zhang
>> http://yz.mit.edu/
>
>



--
Yang Zhang
http://yz.mit.edu/

Yang Zhang
Joined: 2010-02-09,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

On Mon, Jul 25, 2011 at 11:12 AM, Jorge Ortiz wrote:
> Yeah, the code I pasted is a toy implementation I banged out in 15minutes
> when Dynamic first came out. It breaks in several ways around primitives,
> but a production-ready implementation would take these things into account.
> Does C#'s Dynamic work even with extension methods? That's interesting. I
> bet with a native Scala reflection library, you could mimic the rules for
> implicit resolution and have implicits work too.

That's a good counterpoint, since it doesn't:
http://stackoverflow.com/questions/258988/will-the-dynamic-keyword-in-c4...

One can dream, though.

>
> --j
> On Mon, Jul 25, 2011 at 3:46 AM, Yang Zhang wrote:
>>
>> Yeah, sorry, should have been more specific - I was thinking C# was a
>> bit more than dynamic method dispatch. For instance, you can do the
>> following with C# dynamic, but not DynamicImpl:
>>
>> dynamic x = 5
>> x = x / 2
>>
>> But for that you can just try to add in all possible primitive
>> operations as special cases. More generally, though, whereas C#
>> dynamic seems to capture the "full expressiveness" of C#, doesn't seem
>> like there's anything here that can capture the equivalent "full
>> expressiveness" of Scala, e.g. run-time implicit conversion
>> resolution. But that's just one extreme in the spectrum of
>> possibilities.
>>
>> BTW, how would you optimize DynamicImpl with invokedynamic?
>>
>> Also, again, no real motivations nor expectations here - just asking
>> out of curiosity/to learn, not to debate.
>>
>> On Sun, Jul 24, 2011 at 5:52 PM, Jorge Ortiz
>> wrote:
>> > Yang,
>> > Scala's Dynamic trait gives you the tools to roll-your-own
>> > implementation of
>> > C#'s Dynamic. Look at the pastie John linked to, or this one, which has
>> > the
>> > same example and another involving XML: https://gist.github.com/783394
>> > How does this not implement the semantics of C#'s Dynamic?
>> > --j
>> > On Sat, Jul 23, 2011 at 11:46 PM, Yang Zhang
>> > wrote:
>> >>
>> >> On Sat, Jul 23, 2011 at 5:02 AM, martin odersky
>> >>
>> >> wrote:
>> >> >
>> >> >
>> >> > On Sat, Jul 23, 2011 at 1:41 PM, Andrew Garman
>> >> >
>> >> > wrote:
>> >> >>
>> >> >> In C# instead of writing:
>> >> >>
>> >> >> var foo = ...
>> >> >> foo.invoke("function1" ...)
>> >> >>
>> >> >> You can write:
>> >> >>
>> >> >> dynamic foo = ...
>> >> >> foo.function1(...)
>> >> >>
>> >> >> Aside from the sugar there is a dynamic dispatch runtime in the .NET
>> >> >> runtime that optimizes the dynamic calls.
>> >> >>
>> >> > Yes, that's precisly what Scala's Dynamic type will also achieve. And
>> >> > JDK
>> >> > 1.7 contributes the invokedynamic instruction to make it fast. I
>> >> > should
>> >> > note
>> >> > that in Scala 2.9, Dynamic is only enabled with -Xexperimental, but
>> >> > it
>> >> > will
>> >> > be a standard feature in Scala 2.10.
>> >>
>> >> Correct me if I'm wrong, but Dynamic appears to be quite different
>> >> from C# dynamic. As Daniel Spiewak points out in
>> >>
>> >>
>> >> https://groups.google.com/forum/#!msg/scala-language/k2RZEOOy_O4/ScVRU5p_TogJ,
>> >> Dynamic basically just gives you missing method interception. Contrast
>> >> this with the overview of C# dynamic here:
>> >> http://msdn.microsoft.com/en-us/library/dd264736.aspx.
>> >>
>> >> --
>> >> Yang Zhang
>> >> http://yz.mit.edu/
>> >
>> >
>>
>>
>>
>> --
>> Yang Zhang
>> http://yz.mit.edu/
>
>

Yang Zhang
Joined: 2010-02-09,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Anything equivalent to C#'s `dynamic`?

I'm now remembering one other pretty big thing that C# dynamic
supports which using Scala Dynamic won't buy you: run-time overload
resolution. If you have multiple overloads of a method and want to
pass in a Dynamic, implicit conversions won't help.

On Mon, Jul 25, 2011 at 11:46 AM, Yang Zhang wrote:
> On Mon, Jul 25, 2011 at 11:12 AM, Jorge Ortiz wrote:
>> Yeah, the code I pasted is a toy implementation I banged out in 15minutes
>> when Dynamic first came out. It breaks in several ways around primitives,
>> but a production-ready implementation would take these things into account.
>> Does C#'s Dynamic work even with extension methods? That's interesting. I
>> bet with a native Scala reflection library, you could mimic the rules for
>> implicit resolution and have implicits work too.
>
> That's a good counterpoint, since it doesn't:
> http://stackoverflow.com/questions/258988/will-the-dynamic-keyword-in-c4...
>
> One can dream, though.
>
>>
>> --j
>> On Mon, Jul 25, 2011 at 3:46 AM, Yang Zhang wrote:
>>>
>>> Yeah, sorry, should have been more specific - I was thinking C# was a
>>> bit more than dynamic method dispatch. For instance, you can do the
>>> following with C# dynamic, but not DynamicImpl:
>>>
>>> dynamic x = 5
>>> x = x / 2
>>>
>>> But for that you can just try to add in all possible primitive
>>> operations as special cases. More generally, though, whereas C#
>>> dynamic seems to capture the "full expressiveness" of C#, doesn't seem
>>> like there's anything here that can capture the equivalent "full
>>> expressiveness" of Scala, e.g. run-time implicit conversion
>>> resolution. But that's just one extreme in the spectrum of
>>> possibilities.
>>>
>>> BTW, how would you optimize DynamicImpl with invokedynamic?
>>>
>>> Also, again, no real motivations nor expectations here - just asking
>>> out of curiosity/to learn, not to debate.
>>>
>>> On Sun, Jul 24, 2011 at 5:52 PM, Jorge Ortiz
>>> wrote:
>>> > Yang,
>>> > Scala's Dynamic trait gives you the tools to roll-your-own
>>> > implementation of
>>> > C#'s Dynamic. Look at the pastie John linked to, or this one, which has
>>> > the
>>> > same example and another involving XML: https://gist.github.com/783394
>>> > How does this not implement the semantics of C#'s Dynamic?
>>> > --j
>>> > On Sat, Jul 23, 2011 at 11:46 PM, Yang Zhang
>>> > wrote:
>>> >>
>>> >> On Sat, Jul 23, 2011 at 5:02 AM, martin odersky
>>> >>
>>> >> wrote:
>>> >> >
>>> >> >
>>> >> > On Sat, Jul 23, 2011 at 1:41 PM, Andrew Garman
>>> >> >
>>> >> > wrote:
>>> >> >>
>>> >> >> In C# instead of writing:
>>> >> >>
>>> >> >> var foo = ...
>>> >> >> foo.invoke("function1" ...)
>>> >> >>
>>> >> >> You can write:
>>> >> >>
>>> >> >> dynamic foo = ...
>>> >> >> foo.function1(...)
>>> >> >>
>>> >> >> Aside from the sugar there is a dynamic dispatch runtime in the .NET
>>> >> >> runtime that optimizes the dynamic calls.
>>> >> >>
>>> >> > Yes, that's precisly what Scala's Dynamic type will also achieve. And
>>> >> > JDK
>>> >> > 1.7 contributes the invokedynamic instruction to make it fast. I
>>> >> > should
>>> >> > note
>>> >> > that in Scala 2.9, Dynamic is only enabled with -Xexperimental, but
>>> >> > it
>>> >> > will
>>> >> > be a standard feature in Scala 2.10.
>>> >>
>>> >> Correct me if I'm wrong, but Dynamic appears to be quite different
>>> >> from C# dynamic. As Daniel Spiewak points out in
>>> >>
>>> >>
>>> >> https://groups.google.com/forum/#!msg/scala-language/k2RZEOOy_O4/ScVRU5p_TogJ,
>>> >> Dynamic basically just gives you missing method interception. Contrast
>>> >> this with the overview of C# dynamic here:
>>> >> http://msdn.microsoft.com/en-us/library/dd264736.aspx.
>>> >>
>>> >> --
>>> >> Yang Zhang
>>> >> http://yz.mit.edu/
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Yang Zhang
>>> http://yz.mit.edu/
>>
>>
>
>
>
> --
> Yang Zhang
> http://yz.mit.edu/
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland