file objects nowadays have ".closed" and ".mode" attributes, but the point
is --
the dispatch mechanism should be able to put constraints on not only on the
*type*, but on the *state* as well -- so once we have multi-dispatch, we
wouldn't need to "manually" check the state of the arguments.
we want to be able to express that in the dispatch itself. imagine this:
def factorial(n):
if n < 0:
raise ValueError
if n < 2:
return 1
return n*factorial(n-1)
where i want to write it as
@dispatched
def factorial(n : (lambda n: 0 <= n < 2)):
return n
@dispatched
def factorial(n : (lambda n: n >= 2)):
return n * factorial(n-1)
also note that no case is defined for (n < 0), which makes it an exception
automatically. this makes it very much like Haskell's pattern matching.
you can see some more info at http://en.wikipedia.org/wiki/ERights
(look for "guard")
-tomer
On 1/17/07, Bill Janssen <[EMAIL PROTECTED]> wrote:
Of course, the purpose of using ABCs is to allow easy inspection of
the capabilities of an object, and for some objects, the state can be
an important part. But don't be misled to confuse ABCs with simply
type-based function dispatch. They're useful for other things as
well.
I think that stateful value types should probably have, as you say,
mechanisms for inspecting that state. For instance, the current
"file" type has a "closed" attribute, doesn't it?
Bill
_______________________________________________
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