Why not do what python does?

drop -2 -- drops the last 2 elements from the list
take -2 -- grabs the last 2 elements from the list

take n list | n<0 = drop (length list + n) list
drop n list | n<0 = take (length list + n) list

If the list is an infinite list, the behavior is equivalent to B.
If the list is finite, these are really useful primitives, like chop() in
perl.

I think this solution also satisfies Chris Okasaki's:  

take n xs ++ drop n xs == xs

(except where the list is infinite)

-Alex-

___________________________________________________________________
S. Alexander Jacobson                   Shop.Com
1-212-697-0184 voice                    The Easiest Way To Shop


On Mon, 24 Jan 2000, Jon Fairbairn wrote:

> > > Take and drop
> > > [..]
> > > 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 vote for (B). 
> 
> Ditto, though I would say that the restriction is that the 
> argument should be a natural number, and its simply a 
> failing of the type system that it cannot express this.
> 
> -- 
> J�n Fairbairn                                 [EMAIL PROTECTED]
> 18 Kimberley Road                                        [EMAIL PROTECTED]
> Cambridge CB4 1HH                      +44 1223 570179 (pm only, please)
> 
> 
> 





Reply via email to