The take-drop law I've always liked is
take n xs ++ drop n xs = xs, for all lists xs and all naturals n.
I agree that (take n _) and (drop n _) should both give errors for n < 0.
On the other hand, I don't buy the argument that (take 1 []) should be
undefined because (head []) is undefined. Since head :: [a] -> a, (head [])
really has no sensible value, but (take n) :: [a] -> [a], so [] is a
reasonable value for (take 1 []).
How about these definitions? They're like the Haskell98 prelude definitions
except that n<0 is always an error, even if the list is [].
> take 0 _ = []
> take n _ | n<0 = error "Prelude.take: negative argument"
> take n [] = []
> take n (x:xs) = x : take (n-1) xs
> drop 0 xs = xs
> drop n _ | n<0 = error "Prelude.drop: negative argument"
> drop n [] = []
> drop n (x:xs) = drop n xs
Or these?
> take n xs
> | n==0 = []
> | n< 0 = error "Prelude.take: negative argument"
> | null xs = []
> | otherwise = x : take (n-1) xs'
> where
> (x:xs') = xs
> drop n xs
> | n==0 = xs
> | n< 0 = error "Prelude.drop: negative argument"
> | null xs = []
> | otherwise = drop (n-1) xs'
> where
> (_:xs') = xs
Regards to all,
--Ham
------------------------------------------------------------------
Hamilton Richards Jr. Department of Computer Sciences
Senior Lecturer Mail Code C0500
512-471-9525 The University of Texas at Austin
SHC 434 Austin, Texas 78712-1188
[EMAIL PROTECTED]
------------------------------------------------------------------