[Python-ideas] Haskell envy
p.f.moore at gmail.com
Mon Apr 23 20:50:14 CEST 2012
On 23 April 2012 17:52, Steven D'Aprano <steve at pearwood.info> wrote:
> I have mixed ideas on this. On the one hand, subsequences is a natural
> function to include along with permutations and combinations in any
> combinatorics tool set. As you point out, Haskell has it. So does
> Mathematica, under the name "subsets".
> But on the other hand, itertools is arguably not the right place for it. If
> we add subsequences, will people then ask for partitions and derangements
> next? Where will it end? At some point the line needs to be drawn, with some
> functions declared "too specialised" for the general itertools module.
> (Perhaps there should be a separate combinatorics module.)
It seems to me that you're precisely right here - it's *not* right to
keep adding this sort of thing to itertools, or as you say it will
never end. On the other hand, it's potentially useful, and not
necessarily immediately obvious.
So I'd say it's exactly right for a 3rd party "combinatorics" module
on PyPI. Or if no-one thinks it's sufficiently useful to write and
maintain one, then as a simple named function in your application.
Once your application has a combinatorics module within it, that's the
point where you should think about releasing that module separately...
Of course, I'm arguing theoretically here. I've never even used
itertools.combinations, so I have no real need for *any* of this. If
people who do use this sort of thing on a regular basis have other
opinions, then that's a much stronger argument :-)
More information about the Python-ideas