[Python-Dev] Re: switch statement

Michael Chermside mcherm at mcherm.com
Thu Apr 21 14:03:45 CEST 2005

Andrew McGregor writes:
> I can post an alternative, inspired by this bit of Haskell
> The intent is that within the case, the bit before each : is a boolean
> expression, they're evaluated in order, and the following block is
> executed for the first one that evaluates to be True.

If we're going to be evaluating a series of booleans, then the One Proper
Format in Python is:

     if <bool-expr-1>:
     elif <bool-expr-2>:
     elif <bool-expr-3>:

When people speak of introducing a "switch" statement they are speaking
of a construct in which the decision of which branch to take requires
time proportional to something LESS than a linear function of the number
of branches (it's not O(n) in the number of branches).

Now the pattern matching is more interesting, but again, I'd need to
see a proposed syntax for Python before I could begin to consider it.
If I understand it properly, pattern matching in Haskell relies
primarily on Haskell's excellent typing system, which is absent in

-- Michael Chermside

More information about the Python-Dev mailing list