Brian Boutel wrote:


> take -2 [1,2,3,4] ++ drop -2 [1,2,3,4] -> [3,4,1,2]

But [1,2,3,4] is NOT the same as [3,4,1,2]. So the equality doesn't hold.

Personally, for reasons I'm not sure I can articulate, I've always strongly
disliked the notion that negative arguments should produce "backwards"
behavior, e.g. "take n xs" == "drop (length xs - n) xs". I think the best
way I can put it is that the simple, easily comprehended definition of,
e.g., "take n xs", is that it gives you the first n items in the list xs,
and that this simple concept is violated, to no significant benefit, by
defining backwards behavior for negative values of n. It is particularly
dangerous in the presence of infinite lists, since the negative value may
result from a bug in the program -- I would rather have the program fail
than have it subtly become non-terminating. (Not that there aren't other
ways of doing this.)

I greatly prefer the suggestion that

    take n xs | n < 0 = []
    drop n xs | n < 0 = xs

Craig


Reply via email to