[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optional types
On Thu, 2001-12-06 at 16:07, shivers@cc.gatech.edu wrote:
> Are we going to typecheck foo's argument when we enter foo? That could involve
> an *arbitrarily large* amount of work -- we have to scan the entire list,
> checking each element. It's proportional to the length of the input list.
> Oooh, ouch.
Dylan's approach might be summarized as:
"A vector which happens to contain nothing but integers is not the same
thing as a vector-of-integers."
The first has the type '<vector>', the second, 'limited(<vector>, of:
<integer>)'.
So you could declare your function as:
define function foo (v :: <vector>) ... end;
...or as:
define function foo (v :: limited(<vector>, of: <integer>)) ... end;
In the former case, the elements of the vector are not type-checked. In
the latter case, the vector must be *created*, up front, as a limited
vector.
(I don't use <list> here because, for some reason, Dylan doesn't allow
<list> to be a limited type.)
> It's a conundrum to me.
If your language has optional types, then it's desirable for all your
types to be checkable in fast, constant time. You can do this for class
types and most parameterized types. This will probably require some
compromises.
To the best of my knowledge, you don't want to try optional types with
just any type system.
Cheers,
Eric