Ord methods are surprisingly strict
Simon Jakobi
simon.jakobi at googlemail.com
Fri May 8 10:56:01 UTC 2020
Sven,
Many thanks for the reference to the Haskell report! Looks like it's
high time for me to finally read it! :)
I think it would be good to reproduce the bits regarding the
strictness of derived instances of Eq and Bool in the base haddocks.
What's still unclear to me is whether library authors are expected to
follow the same strictness semantics in their Ord instances. For
example, if I were to expose my Const type with its lazy Ord instance
from a library, would that be surprising for users of the library?
Could someone illustrate in what kind of issues the reduced strictness
might manifest?
Thanks,
Simon
Am Do., 7. Mai 2020 um 20:00 Uhr schrieb Sven Panne <svenpanne at gmail.com>:
>
> Am Do., 7. Mai 2020 um 15:26 Uhr schrieb David Feuer <david.feuer at gmail.com>:
>>
>> I believe this is all about strictness analysis. If these were lazy, then users would have to be very careful to force the lazy arguments when they don't need that laziness to avoid building unnecessary thunks.
>
>
> This argument holds basically for every potentially lazy function, and I fail to see why comparisons should be special, so this is not really convincing. :-) We have easy ways to make things more strict, but not the other way around.
>
> In any case, it has historically been the case that the reference implementations in the Haskell language/library report define the strictness of the defined functions, too. Otherwise things could be very surprising, in both ways (too lazy, too strict). Furthermore, the report is *very* explicit about the derived instances: https://www.haskell.org/onlinereport/haskell2010/haskellch11.html#x18-18300011.1 And (), Bool, ... are defined via deriving: https://www.haskell.org/onlinereport/haskell2010/haskellch9.html#x16-1710009
More information about the Libraries
mailing list