On 5/19/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 5/18/06, Kay Schluehr <[EMAIL PROTECTED]> wrote: > > I have a question to the audience. How do you represent higher order > > functions using this syntax? > > I think Collin and I both (independently) proposed the pragmatic > Function(<type>, <type>, ..., returns=<type>) for this.
Based on a suggestion from Nick Coghlan [1], I'm now favoring something like this: Function(<type>, <type>, required_keyword=<type>, ...).returns(<type>) The idea would be that you can use keyword arguments to Function to assert that the passed-in function object supports being called with certain keyword arguments. That is, if you were planning to call a passed-in function like so: func(5, 6, abc=7) you'd want to assert that func actually has a parameter named 'abc'. The corresponding Function would be Function(Number, Number, abc=Number). Using a 'returns' keyword argument to Function would effectively prohibit you from making sure that a function has a parameter named 'returns'. Hence, the returns() method. As I mentioned [2], you can play around with this model using the trunk/ version of typecheck [3] (with docs for Function() [4]). This is by no means set in stone, so comment away. The main point I'm not entirely happy with: the use of star() and double_star() methods to indicate types for *vargs and **kwargs, respectively. If you like this general approach to handling Function(), I'll sketch out a version of Generator along the same lines. Collin Winter [1] - http://mail.python.org/pipermail/python-3000/2006-May/002033.html [2] - http://mail.python.org/pipermail/python-3000/2006-May/002061.html [3] - http://oakwinter.com/code/typecheck/dist/typecheck-svn-latest.tar.gz [4] - http://oakwinter.com/code/typecheck/dev/utility/function.html _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
