Brian Boutel <[EMAIL PROTECTED]> wrote:
> We have seen various proposals about what laws should hold wrt
> take and drop. I think there is a reasonable presumption that the
> following very simple laws should hold first:
>
> length (take n xs) === n
> length (drop n xs) === length xs -n
Does that not imply that "take n xs" when n > (length xs) should be an
error? I would support that for Haskell 2000, but not for Haskell 98; it's
too big a change, and goes far beyond the original goal of resolving the
problem of "take n xs | n < 0".
For Haskell 98, I still favor the proposal:
take n xs | n < 0 = []
drop n xs | n < 0 = xs
For Haskell 2000, I feel that the list functions should be consistent in
their treatment of empty lists. If "head []" is an error, then "take 2 [1]"
should also be an error. And I like having "head []" be an error, because if
it returned [], then it seems to me that that would have nasty implications
for pattern-matching. I don't want a pattern like "(x:xs)" to match the
empty list, which it presumably would if "head []" and "tail []" did not
fail (x and xs would both be bound to []).
So, if "head []" and "tail []" are going to fail, then other things that
imply looking at the head or tail of [] should also fail, including "take 2
[1]" and "drop 2 [1]".
Craig