[Haskell-cafe] Ord methods too strict?
Li-yao Xia
lysxia at gmail.com
Wed Jan 2 15:06:57 UTC 2019
Hi Vilem,
> This is not just about crashing. (I’m using `undefined` as a way of
> making strictness explicit.) `False >= veryExpensiveComputation`
> should return `True` immediately without any unnecessary computation.
There is also an opposite situation, where evaluating the second
argument allows us to free a lot of memory, as that argument would
otherwise remain a thunk with references to many things.
> Also it doesn’t seem like a special case: this makes sense for any
partially ordered Type with a top and/or bottom element.
That may be acceptable with Bool because its values are small. But to
compare two pairs `(a,b) <= (x,y)` we would have to first traverse
`(a,b)` to decide whether it's the smallest element, before evaluating
the second argument to WHNF and comparing component-wise. Besides the
extra complexity (both in code and in run time), this would not be less
strict than the current default, since the first argument could get
completely evaluated before even looking at the second one: `(False,
_|_) <= (True, True) = _|_` (currently, this is `True`). We also would
not know whether the type (a, b) has a smallest element without stronger
constraints than (Ord a, Ord b), so this optimization is really only
practically feasible for types with a nullary first constructor.
Li-yao
More information about the Haskell-Cafe
mailing list