Chris Okasaki writes:
| But if the type *says* Int, then it should have reasonable behavior
| for ints.  I look at the negative case as being equivalent to
| standard mathematical treatment of ranges such as i..j, where the
| range is considered to be empty if j < i.  Allowing take/drop to
| handle negative arguments should be useful to exactly the same
| extent as that mathematical convention.

I find this persuasive.  That suggests these definitions:

> take _ [] = []
> take n _ | n <= 0 = []
> take (n+1) (x:xs) = x : take n xs

> drop _ [] = []
> drop n xs | n <= 0 = xs
> drop (n+1) (_:xs) = drop n xs

> splitAt n xs = (take n xs, drop n xs)

The call some have made for the tightest possible error
checking also has merit, however.  That would suggest
these definitions:

> takeExactly 0 _ = []
> takeExactly (n+1) (x:xs) = x : takeExactly n xs
> takeExactly _ _ = undefined

> dropExactly 0 xs = xs
> dropExactly (n+1) (_:xs) = dropExactly n xs
> dropExactly _ _ = undefined

> splitAtExactly n xs = (takeExactly n xs, dropExactly n xs)

I would say that the more loosely-defined functions definitely
belong in the library and that it is a matter of taste whether
or not to include the tighter ones.

Cheers,
--Joe

Joseph H. Fasel, Ph.D.              email:  [EMAIL PROTECTED]
Technology Modeling and Analysis    phone:  +1 505 667 7158
University of California            fax:    +1 505 667 2960
Los Alamos National Laboratory      postal: TSA-7 MS F609
                                            Los Alamos, NM  87545


Reply via email to