What Is Good About Haskell?
Python may be terrible, but this poster doesn&#x27;t know Python at all. Here&#x27;s how to fix the first snippet:<p><pre><code>    leaf = object()
</code></pre>
Huh, that&#x27;s funny, it&#x27;s <i>shorter</i> than the Haskell? Why is that? Let&#x27;s keep going.<p><pre><code>    def merge(lhs, rhs):
        if lhs is leaf: return rhs
        if rhs is leaf: return lhs
        if lhs[0] &lt;= rhs[0]: return lhs[0], merge(rhs, lhs[2]), lhs[1]
        return rhs[0], merge(lhs, rhs[2]), rhs[1]
</code></pre>
Ugh. My mouth tastes funny. Livecoding on this site is always disorienting. I need to sit down for a bit. Exercise for the reader: Continue on in this style and figure out whether the Haskell really deserves its reputation for terseness and directness.<p>Edit: I kept reading and was immediately sick. __dict__ abuse is a real problem in our society, folks. It&#x27;s not okay.<p><pre><code>    def insert(tree, elt): return merge(tree, (elt, leaf, leaf))
</code></pre>
The Haskell memes are growing stronger as I delve deeper into this jungle. The pop-minimum function here is a true abomination, breaking all SOLID principles at once. I can only imagine what it might look like in a less eldritch setting:<p><pre><code>    def popMin(tree):
        if tree is leaf: raise IndexError(&quot;popMin from leaf&quot;)
        return tree[0], merge(tree[1], tree[2])
</code></pre>
We continue to clean up the monstrous camp.<p><pre><code>    def listToHeap(elts):
        rv = leaf
        for elt in elts:
            rv = insert(rv, elt)
        return rv
</code></pre>
The monster...they knew! They could have done something better and chose not to. They left notes suggesting an alternative implementation:<p><pre><code>    def listToHeap(elts): return reduce(insert, elts, leaf)
</code></pre>
Similarly, if we look before we leap:<p><pre><code>    def heapToList(tree):
        rv = []
        while tree is not leaf:
            datum, tree = popMin(tree)
            rv.append(datum)
        return rv
</code></pre>
And again, the monster left plans, using one of the forbidden tools. We will shun the forbidden tools even here and now. We will instead remind folks that Hypothesis [0] is a thing.<p>Haskell&#x27;s an alright language. Python&#x27;s an alright language. They&#x27;re about the same age. If one is going to write good Haskell, one might as well write good Python, too.<p>[0] <a href="https:&#x2F;&#x2F;hypothesis.works&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hypothesis.works&#x2F;</a>