[Haskell-cafe] Unnecessarily strict implementations

Henning Thielemann schlepptop at henning-thielemann.de
Thu Sep 2 09:08:53 EDT 2010

Jan Christiansen schrieb:
> Hi,
> On 02.09.2010, at 01:35, Daniel Fischer wrote:
>> It's not that it's not as non-strict as possible per se. (Sorry, had
>> to :)
>> It's that intersperse's current definition (in GHC at least) can cause a
>> space leak. In this case, making the function less strict can cure it, in
>> other cases, more strictness might be the solution.
> I would be very happy if you would share this example with me. I am
> looking for an example where the current implementation of intersperse
> or inits causes a space leak for quite a while now.

I'm also annoyed by several space leaks. These are implementation
artifacts, but they seem to be hard to avoid by the existing
implementations. You cannot reason about space leaks, right? That's a pity.

> I think this is a matter of elegance rather than a matter of efficiency.
> In the same way as I prefer
>   False && _|_ = False
> over
>   False && _|_ = _|_

I think this one is justified by the law:
  filter p (filter q xs) = filter (\x -> q x && p x) xs
 which only hold with the first definition of (&&). E.g.
  q x = x/=0
  p x = div n x

More information about the Haskell-Cafe mailing list