Constraints on definition of `length` should be strengthened
Sven Panne
svenpanne at gmail.com
Sun Apr 9 19:24:12 UTC 2017
2017-04-09 2:01 GMT+02:00 Ben Franksen <ben.franksen at online.de>:
> Am 08.04.2017 um 04:03 schrieb Anthony Clayden:
> > [...] 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.
>
Exactly.
>
> > 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.
>
Yep. :-)
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? [...]
>
And even if there are laws which hold for those instances, it doesn't mean
that these instances should be defined. Take e.g. Bool: One can define a
"Num Bool" instance which respects the usual laws (interpreting Bool
basically as a "Word1", just like Word32 etc.), but we do *not* want to
have this in the standard language/libraries, and for a good reason: It
would make types less useful, removing a part of the usual "If it compiles,
it works" safety net...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20170409/22034b5e/attachment-0001.html>
More information about the Libraries
mailing list