[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Static typing in Lua
- From: Gavin Wraith <gavin@...>
- Date: Thu, 27 Jul 2006 19:37:25 +0100
In message <email@example.com> you wrote:
> > I think nil has to have every type.
> I disagree. Nils are often "generated" by accidentally forgetting last
> function parameter(s) or return value in some of function branches.
I am sorry, you evidently misunderstood what I meant. My fault for
not expressing myself clearly. What I meant was that in a statically
typed language (which Lua is not, but I am musing about what
aspects of Lua could be consistent with static typing), it would be
necessary for nil to be a polymorphic value. So, were one foolish enough
to make the definition of mul_div that you mention and type it as
(int,int,int) -> int then the nil result you mention would be a nil
of type int. If nil is the value of an unassigned variable x and
x has been typed as type t, then that nil is the nil of type t, if you
see what I mean.
How to type errors in a strongly typed language has always been a
thorny subject in the semantics of type theories.
Obviously, there is no hope for strongly typing things like arrays.
However, it seems to me that by making a distinction between
hashes and lists at the user level, and not just internally as Lua
does, there is a possibility for some optimization. At present,
I presume, when table accesses/assignments take place within a
loop, the interpreter has to check which part, hash or list, is
actually being accessed, each time round. If there were a distinction
(as between hashes and arrays, as in Perl, say) then the check code
could be lifted out of the loop.
Gavin Wraith (firstname.lastname@example.org)
Home page: http://www.wra1th.plus.com/