[Python-Dev] Re: switch statement

Michael Walter michael.walter at gmail.com
Thu Apr 21 14:46:42 CEST 2005

On 4/21/05, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Michael Chermside wrote:
> > 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
> > Python.
> There's no real need for special syntax in Python - an appropriate tuple
> subclass will do the trick quite nicely:

You are missing the more interesting part of pattern matching, namely
that it is used for deconstructing values/binding subvalues. Ex.:

case lalala of
  Foo f -> f
  Bar (Baz brzzzzz) _ meep -> (brzzzzz, meep)

or Python-ish:

match doThis() with:
  Foo as f: return f
  (_,* as bar,_): return bar
  Baz(boink as brzzz, meep=10): return brzzz

"* as bar" is Not Very Nice (tm) :/


More information about the Python-Dev mailing list