[Haskell-cafe] Foldable for (,)

Andrey Sverdlichenko blaze at ruddy.ru
Wed May 3 17:11:44 UTC 2017


This is probably twentieth time this question arises. Discussion quickly
boils down to people liking convenient syntax sugar Foldable instance gives
(traverse pair, etc), versus people who don't like absurd semantic which
becomes correct with such instances.

Personally, I'm in the second camp, but Foldable instance isn't going
anywhere. But alternative Prelude is always the option.

On Wed, May 3, 2017 at 11:37 AM Michael Orlitzky <michael at orlitzky.com>
wrote:

> 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.
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170503/ec73011d/attachment.html>


More information about the Haskell-Cafe mailing list