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

Re: Optional types



On Fri, 2001-12-07 at 13:02, Dan Weinreb wrote:
> What you might do is say that the first is of class '<vector>', and
> the second is of class 'limited(<vector>, of: <integer>)'.  But types
> need not correspond in a one-to-one-onto way with classes (as in the
> Curl example I mentioned recently).

This is how it works in Dylan.  To be precise, <class> is a subclass of
<type>. ;-)

> Obviously there are tradeoffs here; the more your type language can
> express things beyond "the value of this variable is an object of
> class X", the more you need a whole syntax and semantics of types that
> goes beyond the syntax and semantics of classes.  I guess you could
> think of such a type language as being a "little language" (in the
> sense that Olin uses the phrase), a special-purpose declarative
> language for writing certain assertions that turn out to be frequently
> useful.

Well, let's start with a basic rule of thumb:

  In an optionally-typed language, adding type declarations should not
  slow down your program.

I'm currently tempted to use a "class / type / contract" breakdown:

1) Every object belongs to a class.  Class membership--even for
parameterized classes--can be tested in a handful of instructions.

2) Variables have types.  Types include classes, foo-or-null types, and
similar beasties.  In an optionally-typed language, all types should be
checkable in O(1) time.

3) More complicated constraints are handled by some sort of
design-by-contract mechanism, with the full power of the language.

I think that if you try to combine (2) and (3), you quickly wind up with
a hairy typesystem and >O(1) typechecks.

Cheers,
Eric