Hi,

This minor inconsistency has been bothering me for some time:

Prelude> drop 10 "test"
""
Prelude> drop (-1) ""
""
Prelude> drop (-1) "a"
"
Program error: Prelude.drop: negative argument

I got these results from Hugs, but the code is identical to that
specified in the Haskell98 standard.

Why not an error for the negative argument on an empty list ?

Secondly, why not an error for an argument that's too big ? What
I would like is this:

drop 0 xs                 = xs
drop n (_:xs) | n>0       = drop (n-1) xs
drop n _      | n>0       = error "Prelude.drop: argument too big"
              | otherwise = error "Prelude.drop: negative argument"

Or is there a good reason for drop being able to drop more
elements than the list is long ? In which case I would like:

drop 0 xs            = xs
drop n []     | n>0  = []
drop n (_:xs) | n>0  = drop (n-1) xs
drop _ _             = error "Prelude.drop: negative argument"

I doubt the second solution would be much less efficient. The first
solution should be just as efficient as the one in Haskell98.

The same goes for take and splitAt.

Regards,
  Jan

Reply via email to