2013/1/19 NN <
nn14...@gmail.com>:
> It is simple.
> The type in the left part is what you expect.
>
> While it is not related to the typing of the right part.
> For instance:
> def a : A = C() : B;
>
> It is same as you type in C#
> A a = (B)(new C());
>
> The right part and the left part has different typing meanings.
>
> So in this case when you try type array , you have same problem.
> The problem that array[...] is array initializer like you have in C# new[] {
> ... }.
> There is no analogue syntax for C# new Type[] {...}.
>
> For instance we could use some special character array<object>[1, ""].
> On the other hand, do you find this feature common ?:)
I think it is intuitive to expect this to work. Nemerle has a pretty
powerful "reasoning" type inference, e.g.
def x = Dictionary()
x["d"] = 4;
is inferred to be string -> int only after typing the second
expression, so I would expect all
this to work fine:
def x = array["d" : object, 4];
def x = array["d", 4] : array[object];
def x : array[object] = array["d", 4];
AFAIR lack of automatic conversion to array[object] is more of a
"warning", e.g. programmer likely made a mistake, so we require him to
express explicity that it using objects was his intention.
In this context I think both
def x = array["d", 4] : array[object];
def x : array[object] = array["d", 4];
make it similarly explicit
>
>
>
>
> On Friday, January 18, 2013 12:15:21 PM UTC+3, Bogdan Mart wrote:
>>
>>
>>
>> четверг, 11 октября 2012 г., 11:36:35 UTC+3 пользователь SprLinx написал:
>>>
>>>
>>> ok, so we say that whenever we want to create an array of objects
>>> initialized that way, we have to put the hint to the compiler, this behavior
>>> is not a bug in compiler but its there because that helps to avoid errors.
>>>
>>> This is coherent with c#:
>>>
>>> def ar = array["hello" : object, DateTime(2012, 10, 10)];
>>> var ar = new object[] {"hello", new DateTime(2012, 10, 10)};
>>>
>>> notice that even with c# we can't omit the object keyword.
>>
>>
>> I thought following code will be more expressive
>>
>> def ar:array[object] = array["hello" , DateTime(2012, 10, 10)];
>>
>> but unfortunatrly it also fails to compile with same error as
>>
>> def ar = array["hello" , DateTime(2012, 10, 10)];
>