[Types-sig] New syntax?

Martijn Faassen faassen@vet.uu.nl
Fri, 17 Dec 1999 18:32:45 +0100

Paul Prescod wrote:
> Martijn Faassen wrote:
> > 
> > ...
> > Didn't you think parameterized types looked fairly straightforward in my
> > syntax proposal?
> I must have missed something. Could you show me how to do Btree of X and
> then make concrete types Btree of Int and Btree of Functions From String
> to Int?

I don't know enough about Btrees to give a good example of that, but this
would be the idea:

# declclass, decldef to define classes and functions of same name
declclass Test: 
    whatevertype: param

    def __init__(self, whatevertype):
        self.data: whatevertype   

    def getvalue(self):
        result: whatevertype

# need to come up with new typedefinition syntax here
# for classes this isn't necessary as a class definition should be a type
# definition, but for functions it may be necesary. This needs to be
# thought out. I think typedeffing functions when necessary is better than
# devising some syntax to declare a function inline in a parametric
# type instantiation.
typedef Func(string):
    result: int

foo: Test(int)
bar: Test(Func)
baz: Test(Test(int))

Something like that. The keywords aren't ideal yet, but the syntax is
fairly Pythonic. 

By the way, I thought of an alternative syntax that might be
more Pythonic as it cuts down on the use of ':'

declclass Foo:
    def __init__(self, value=[int]):
        self.data = [int]
        self.moredata = string
    def dosomething(self, one=int, two=string):
        three = [int]
        return int

This one might be more Pythonic and I think I'll advocate this syntax
from now on. :) Transform to external interface by removing all type
assignments to local variables. Transform to interface without exposing 
member data by removing all type assignments in method bodies.

Did you all notice how the terms 'type assignment' and 'type instantiation'
nicely map to Pythonic syntax?