[Types-sig] List of FOO

Martijn Faassen m.faassen@vet.uu.nl
Wed, 15 Dec 1999 10:53:42 +0100


Paul Prescod wrote:
> 
> Martijn Faassen wrote:
> >
> > I agree completely, and one *can* express most of this pretty easily in
> > current Python, i.e.:
> >
> > types = {
> >     "bar": IntType,
> >     "baz": ListType(IntType),
> >     "hey": IntType,
> >     "foo3": FunctionType(args=(IntType,), result=IntType),
> >
> >     "crazy" : ListType(FunctionType(args=(ListType(IntType),
> > StringType),                                 result=DictType(StringType,
> >
> > FunctionType(args=None,
> > result=StringType)))
> > }
> 
> Questions:
> 
> 1. This system is supposed to be extensible, right? So I could, for
> instance, define a binary tree module and have "binary trees of ints"
> and "binary trees of strings." How do I define the binary tree class and
> state that it is parameterizable?

Good question; so far I only thought about making built in types (such
as list) parameterizable. One could however do something similar with
classes, though:

__typedefs__ = {
"parameterized_class" : ParameterizedClassTypeDef(parameters=('foo',),
                          members = {
                            "alpha" : 'foo',
                            "beta" : IntType
                          }
                        )

}

__types__ = {
  "integer_class" : ParameterizedClassType('parameterized_class', 
                      parameters = { "foo" : IntegerType })
}
 
Something like that, at least. I know it looks absolutely horrible, but
it's workable. :)
                                             
> 2. How does this work with interfaces? "ListType" is cheating. We need
> SequenceType because that's not implementation specific. And
> SequenceType needs to be defined by an interface, not a class.

I just basically took the standard module types and replaced them with
parameterizable classes, but you could come up with SequenceType if you
like. I'm often in quite an OPT frame of mind. But even outside that,
ListType does say something about the interface. A TupleType parameter
cannot be changed inside the function, but a ListType parameter can.
That's a huge difference for the interface.
 
> 3. What does "tuple of int, string" look like? And should we have list
> length parameters?

I haven't fully worked this out yet, but you can fill in details
yourself. :)

HeterogenousTupleType(elementtypes = (IntType, StringType))

I don't know if we should have list length parameters.

Regards,

Martijn