Simon Peyton-Jones wrote:
> Take and drop
> ~~~~~~~~~~~~~
> Jan Kort points out that
>
> a) (take n xs) and (drop n xs) are defined for n > length xs
> In that case they do something reasonable and useful
> (take gives back xs, drop gives the empy list)
>
> b) They are both also defined if the list is empty, regardless of
> the value of n
>
> c) But iff the list is non-empty, they fail for n < 0.
>
> This seems bizarre. I can see three alternatives:
>
> (A) Make them defined for any n. If n < 0, do something reasonable:
> take: give empty list
> drop: give whole list
>
> (B) Make them defined for n > length xs, but fail for n < 0.
>
> (C) Status quo
>
> PROPOSAL: Use alternative (A)
I have argued in favor of A in the past. It's the asymmetry
that bothers me -- if n < 0 is an error, then n > length xs
should be also. (Making both errors would I suppose be
alternative D.)
One advantage of A is that it satisfies the law that
take n xs ++ drop n xs == xs
for any (terminating) n, as opposed to requiring a side
condition like n >= 0.
Chris