[Python-3000] Type annotations: annotating generators
Greg Ewing
greg.ewing at canterbury.ac.nz
Sun May 21 08:54:14 CEST 2006
Guido van Rossum wrote:
> I guess by "algebraic types" you meant enumerated types?
An algebraic type is somewhat more than that -- think
of it as something like a tagged tuple.
A less degenerate example would be (using a more
Haskell-like syntax):
Tree t = Leaf t | Node (Tree t) (Tree t)
This says that a Tree of items of type t is either a
Leaf containing something of type t, or a Node containing
two other things of type Tree of t.
Leaf and Node can then be used as functions that construct
data items, e.g.
let x = Node (Leaf 1) (Node (Leaf 2) (Leaf 3))
An equivalent Python data structure might be something like
x = ('Node', ('Leaf', 1), ('Node', ('Leaf', 2), ('Leaf', 3)))
Which wouldn't be all that useful unless you could to
Haskell-style pattern matching on it as well. So you're
probably right that algebraic types don't really belong
in Python.
--
Greg
More information about the Python-3000
mailing list