Dynamic<T> and anonymous objects

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic<T> and anonymous objects

Justin Donaldson-3
I feel that this has come up before, but I couldn't find a reference or resolution... apologies if it is a repeat.

Why is cast necessary here?:

        var o:Dynamic<Dynamic> = cast {
            foo: 1,
            bar: 'baz'
        }


The following will work without declaring o's type:

        var o = {
            foo: 1,
            bar: 3
        }


"o" is automatically typed as Dynamic<Int> in that case. If a field has a different type (e.g. String) than the rest, the object then just takes on a stricter structural type.

It would be nice to easily type dynamic anonymous objects to distinguish them from other anonymous values.  For instance, I would think that all anonymous objects would be Dynamic<Dynamic>.

Best,
-Justin
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic<T> and anonymous objects

Tony Polinelli
Maybe it would be better if they were dynamic until defined as
stricter- I think this makes sense- then it is more expressive for
anonymous objects, but still allows strictness

There wouldnt be any performance gains od Dynamic<int> over
Dynamic<Dynamic> anyway would there?

On Thursday, July 21, 2011, Justin Donaldson <[hidden email]> wrote:

> I feel that this has come up before, but I couldn't find a reference or resolution... apologies if it is a repeat.
>
> Why is cast necessary here?:
>
>         var o:Dynamic<Dynamic> = cast {
>             foo: 1,
>             bar: 'baz'
>         }
>
> The following will work without declaring o's type:
>
>         var o = {
>             foo: 1,
>             bar: 3
>         }
>
>
> "o"
>  is automatically typed as Dynamic<Int> in that case. If a field
> has a different type (e.g. String) than the rest, the object then just
> takes on a stricter structural type.
>
> It would be nice to easily type dynamic anonymous objects to distinguish them from other anonymous values.  For instance, I would think that all anonymous objects would be Dynamic<Dynamic>.
>
> Best,
> -Justin
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic<T> and anonymous objects

Justin Donaldson-3
This isn't really a performance issue.  Essentially I want to distinguish Dynamic (objects and primitives) from Dynamic<Dynamic> (objects) through typing.  The latter are guaranteed to have fields, so you can skip some runtime checks for their basic type... I suppose Dynamic<Dynamic> could enable some better performance in this small sense.

-Justin


On Wed, Jul 20, 2011 at 3:04 PM, Tony Polinelli <[hidden email]> wrote:
Maybe it would be better if they were dynamic until defined as
stricter- I think this makes sense- then it is more expressive for
anonymous objects, but still allows strictness

There wouldnt be any performance gains od Dynamic<int> over
Dynamic<Dynamic> anyway would there?

On Thursday, July 21, 2011, Justin Donaldson <[hidden email]> wrote:
> I feel that this has come up before, but I couldn't find a reference or resolution... apologies if it is a repeat.
>
> Why is cast necessary here?:
>
>         var o:Dynamic<Dynamic> = cast {
>             foo: 1,
>             bar: 'baz'
>         }
>
> The following will work without declaring o's type:
>
>         var o = {
>             foo: 1,
>             bar: 3
>         }
>
>
> "o"
>  is automatically typed as Dynamic<Int> in that case. If a field
> has a different type (e.g. String) than the rest, the object then just
> takes on a stricter structural type.
>
> It would be nice to easily type dynamic anonymous objects to distinguish them from other anonymous values.  For instance, I would think that all anonymous objects would be Dynamic<Dynamic>.
>
> Best,
> -Justin
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic<T> and anonymous objects

Justin Donaldson-3
After talking with Franco, we also think it would be useful to better distinguish:

Dynamic<Dynamic>, Dynamic,  and {}.

AFAIK Dynamic and {} are treated the same in the latest svn build.  "{}" seems to imply some sort of anonymous object, but you can also pass primitives for this type.

Whether or not a change is made, we should add some clarification to:
http://haxe.org/ref/dynamic

I'm sure there's some nasty type inference problem lurking there... but, at least we can make the limitations and semantics clear.

Thanks,
-Justin


On Wed, Jul 20, 2011 at 3:51 PM, Justin Donaldson <[hidden email]> wrote:
This isn't really a performance issue.  Essentially I want to distinguish Dynamic (objects and primitives) from Dynamic<Dynamic> (objects) through typing.  The latter are guaranteed to have fields, so you can skip some runtime checks for their basic type... I suppose Dynamic<Dynamic> could enable some better performance in this small sense.

-Justin



On Wed, Jul 20, 2011 at 3:04 PM, Tony Polinelli <[hidden email]> wrote:
Maybe it would be better if they were dynamic until defined as
stricter- I think this makes sense- then it is more expressive for
anonymous objects, but still allows strictness

There wouldnt be any performance gains od Dynamic<int> over
Dynamic<Dynamic> anyway would there?

On Thursday, July 21, 2011, Justin Donaldson <[hidden email]> wrote:
> I feel that this has come up before, but I couldn't find a reference or resolution... apologies if it is a repeat.
>
> Why is cast necessary here?:
>
>         var o:Dynamic<Dynamic> = cast {
>             foo: 1,
>             bar: 'baz'
>         }
>
> The following will work without declaring o's type:
>
>         var o = {
>             foo: 1,
>             bar: 3
>         }
>
>
> "o"
>  is automatically typed as Dynamic<Int> in that case. If a field
> has a different type (e.g. String) than the rest, the object then just
> takes on a stricter structural type.
>
> It would be nice to easily type dynamic anonymous objects to distinguish them from other anonymous values.  For instance, I would think that all anonymous objects would be Dynamic<Dynamic>.
>
> Best,
> -Justin
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org