lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 9 November 2015 at 22:32, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> Now here is a hypothetical question - if Lua had been statically typed
>> language - what would the ideal expression be for this kind of type
>> coercion?
>
> If Lua was statically typed, it would know the type of the expression.
> Either it has the correct type or the wrong type. In both cases type
> coercion seems useless.
>

That is true if there was no type such as 'any'. I mean a system that declares:

local x as table of any

is also statically typed, but the type is declared to be 'any'.

The statically typed languages I am familiar with all appear to
support type conversion operators although this is usually to support
polymorphism.

With Ravi of course there is a the special problem of bridging dynamic
typing with static typing.

When I declare:

local x: integer[] = {1}
local i: integer = x[1]

No coercion is needed as compiler can tell that the expected type if
x[1] is an integer so no problem.

But in the example cited earlier this static analysis is not possible.

Regards
Dibyendu