Constraints on definition of `length` should be strengthened
Ben Franksen
ben.franksen at online.de
Sun Apr 9 00:01:35 UTC 2017
Am 08.04.2017 um 04:03 schrieb Anthony Clayden:
>> On Tue Apr 4 06:50:55 UTC 2017, Sven Panne wrote:
>>> 2017-04-04 8:15 GMT+02:00 Vladislav Zavialov:
>>>> Tuples are unbiased cartesian products, full stop.
>>>
>>> This statement is not correct.
>
>> According to probably all the math books in the world,
>> the statement is correct,
>> at least if we want to see tuples as cartesian products.
> ..
>
> Sven, I have a lot of sympathy with the digruntlement about
> Foldable `length` over tuples.
> But if you're going to start appealing to math,
> you'd better get your math correct.
>
> Whether or not tuples are unbiased,
> even wikipedia will tell you they're not commutative.
>
> So to take your examples from an earlier thread,
> what do you expect Haskell to do here?:
>
> maximum (True,2) => ?
> minimum ((3, 4),5) => ? -- i.e. :: ((Int, Int), Int)
> sum (7,3.14) => ? -- i.e. :: (Int, Double)
> product (Left $ error "Errk") => ? -- i.e. ::
> Either e Int
I (and others) think these should be type errors.
> Do you expect Foldable (a, a) to behave differently
> vs Foldable (b, a) vs Foldable ((a, a), a) vs ...?
>
> Let's get everybody agreed on that.
It would be nice if we could all agree on removing these instances.
BTW, I find it remarkable that of those who defend these instances, few
seem to be especially interested in clarifying the OP's question: what
laws exactly do we expect for Foldable?
It has been stated that "obviously" length (1,2) must be 1 ("what else
could it be?"). This suggests that there is a law for length that makes
this obvious and its ommision in the docs was just an oversight.
Cheers
Ben
More information about the Libraries
mailing list