[Types-sig] New syntax?

Greg Stein gstein@lyra.org
Fri, 17 Dec 1999 21:03:17 -0800 (PST)


On Fri, 17 Dec 1999, Tim Peters wrote:
>...
> If I had a lot of binary integer functions to declare, I would probably use
> a typedef, a la
> 
>     decl typedef BinaryFunc(_T) = def(_T, _T) -> _T
>     decl typedef BinaryIntFunc = BinaryFunc(Int)
>     ...
>     decl var intHandlerMap: {string: BinaryIntFunc}
>     decl var floatHandlerMap: {string: BinaryFunc(Float)}

Okay, Tim. I'm going to stop you right here :-)

The problem with using "decl" to do typedefs is that it does weird voodoo
to associate the typedecl with the name (e.g. BinaryFunc). I believe my
unary operator is much clearer to what is happening:

  BinaryIntFunc = typedef BinaryFunc(Int)

In this case, it is (IMO) very clear that you are storing a typedecl
object into BinaryIntFunc, for later use. For example, we might see the
following code:

  import types
  Int = types.IntType
  List = types.ListType
  IntList = typedef [Int]
  ...


Hrm. I don't have a ready answer for your first typedef, though. That is a
new construct that we haven't seen yet. We've been talking about
parameterizing *classes*, rather than typedecls.

*ponder*

>...
> You're not going to get the same level of expressiveness in an
> imperative-style Python syntax:  it's the right tool for the wrong job.  A
> type-expression sublanguage with one operator ("|") should suffice.

"or" is more Pythonic.

> [on varargs]
> > Me neither. Perhaps something like:
> >
> > decldef foo(first=int, second=string, *[int]):
> >     return int
> >
> > i.e. all the extra arguments must be ints.
> 
> Hmm!  You and Greg both seem to think varargs get implemented as lists
> <wink>.

Bite me. :-)

You do raise a good point in another post, however:

  def foo(*args: (Int)):

Looks awfully funny. For a Python programmer, that looks like grouping
rather than a tuple. If it had a comma in there, then it would look like a
tuple. But of course: there will never be more than one typedecl inside
there, so whythehell is there a comma?

*grumble*  .... I don't have a handy resolution for this one.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/