(sorry, can't remember the original author)
> | The correct definitions would be:
> |
> | take -2 -- drops the last 2 elements from the list
> |               (takes everything except the last 2 elements)
> | drop -2 -- grabs the last 2 elements from the list
> |               (drops everything except the last 2 elements)
> |
> | drop n list | n<0 = drop (length list + n) list
> | take n list | n<0 = take (length list + n) list
> |
> | These are also sane definitions..
Er what happens when I do 
  drop (-1) []
?

Personally I think the whole idea of interpreting negative numbers in a totally
different way to non-negative numbers is absolutely barking.  
For me, "drop (-1)" should produce an error, as it's almost certainly a bug.
In any case I think the rule that where everything is defined
   (drop (x+y)) = (drop x) . (drop y)
should be preserved.

The other problem is what to do about "take n x" and "drop n x" when 
length x < n.  I think there are two solutions:
   (1) raise an error.  This is the easiest solution, and is anyway not so
       bad, as it is easy to explain and catches a probable bug.  But if the
       user wants more sophisticated behaviour it is easy for them to write 
       a more general version.  
   (2) But if that's not allowed I suggest that the functions return 
       "x" and "[]" respectively.

Reply via email to