[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: From dynamic to static
- From: David Given <dg@...>
- Date: Mon, 31 Oct 2005 21:51:20 +0000
On Monday 31 October 2005 18:24, Chris Marrin wrote:
> But this cannot be known at compile time in Lua (or any other
> dynamically typed language that I know of). At compile time o may not
> have a method1 function. But it hopefully will by the time it gets called.
Hence why I said you'd have to use a subset of the language. You'd have to
tell the type analyser that method1 was defined on *some* class. (In fact, if
you didn't, the type analyser should fail, because no object type would be
compatible with it.)
The type analyser would have to know (a) what a constructor looks like; (b)
what a method declaration on a particular class looks like; and (c) how to
find out what the type of a value stored in a table is (statically). It might
be necessary to decree that if x.foo is of one particular type, then y.foo
must be that same type, unless you were willing to find a way of declaring
typed structures. (Of course, class instances are already typed, so you could
manage it in the case of instance variables.)
You'd also need a limitation on variable assignments to one particular type.
local foo = 7
foo = "bar"
...would fail a type constraint. However, this also means that:
local foo = 7
foo = bar()
...would mean that, for it to be valid, bar() must return a number.
In the interests of sanity, it would probably be necessary to disallow
table[key] syntax, or else decree that it bypasses the type safety --- I
don't know how you'd manage to work that work sensibly otherwise. However, if
you were going to be using this strongly-typed Lua, you'd probably want to
use container classes for data storage anyway, and wouldn't need it... this
would also allow such nifty features as a polymorphic Array class that leaves
the type of its members undefined, so that each instance can store a
different strongly-typed value...
You know, this actually sounds *possible*. Good grief.
+- David Given --McQ-+
| firstname.lastname@example.org | "Never attribute to malice what can be adequately
| (email@example.com) | explained by stupidity." --- Nick Diamos
+- www.cowlark.com --+
Description: PGP signature