[Haskell-cafe] Foldable for (,)

Michael Orlitzky michael at orlitzky.com
Wed May 3 15:34:07 UTC 2017


On 05/03/2017 04:44 AM, Chris Smith wrote:
> I'm also interested in Jonathon's question, so let me try to bring
> things back to the question.  Everyone agrees that there's only one
> reasonable way to define this instance if it exists.  But the question
> is: why is it defined at all?
> 

`const 42` is an equally-reasonable implementation to me. If the output
is nonsense, who cares what particular nonsense it is?

These are all objectively stupid results:

  length (2,3) = 1
  product (2,3) = 3
  sum (2,3) = 3
  or (True,False) = False

Of course you can make up some reasoning that will result in that
behavior. For example,

  * the type ((,) a) must be Traversable
  * all Traversables should be Foldables
  * the "length" function should work on Foldables
  * `const 1` is a fine implementation of length
  .. etc.

(Those are by no means the only assumptions that would lead to the same
results.)

But normally, when you have a set of assumptions that result in garbage,
you don't just shrug and try to convince yourself that maybe the
conclusions aren't so bad after all. The point of the type system is not
to put stupid behavior on solid theoretical grounds; it's to reject
incorrect programs, and "length (2,3)" is an incorrect program.

By analogy, ask the same question about, say, PHP.

Question: why is "foo" == TRUE in PHP?
Answer: it makes perfect sense, once you understand blah blah herp derp.

No, it's stupid, and your reasoning is stupid if you can justify it.



More information about the Haskell-Cafe mailing list