[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A question of type assertion
- From: Dibyendu Majumdar <mobile@...>
- Date: Mon, 9 Nov 2015 22:00:10 +0000
Hi,
As I progress with Ravi I often wish there was a way to perform type
assertion or coercion in the language. For example:
local t = { 1 }
local i: integer = t[1]
Above fails in Ravi as the compiler cannot know that the value
returned from t[1] is an integer.
It would be nice to be able to say:
local i: integer = t[1] as integer
Or some such like.
Language support is essential for performance reasons; Ravi already
supports type coercion of function return values. So following already
works.
function asinteger(a) return a end
local i: integer = asinteger(t[1])
Problem is this is bad for performance.
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?
Regards
Dibyendu