On Tue, 25 Jan 2000, BYRNE, Peter wrote:
> (2) If take and drop are to be defined for negative integers, what happens
> to
> take (-n) xs
> when n > len xs? Judging from the definitions proposed:
> take (-5) [1..4] == [1,2,3]
> and things look less useful than confusing.
The python behavior is:
take n list | length list + n < 0 = []
drop n list | length list + n < 0 = list
I think this is the correct complement (dual?) of:
take n list | length list - n < 0 = list
drop n list | lenght list - n > 0 = []
(the current behavior)
The consistent overall behavior on "abc" results in this:
-3 -2 -1 0 1 2 3
take "" "a" "ab" "abc" "a" "ab" "abc"
drop "abc" "bc" "c" "" "bc" "c" ""
(take n list) ++ (drop n list) == list
This is sane and consistent with itself and python.
-Alex-
___________________________________________________________________
S. Alexander Jacobson Shop.Com
1-212-697-0184 voice The Easiest Way To Shop
> > -----Original Message-----
> > From: S. Alexander Jacobson [SMTP:[EMAIL PROTECTED]]
> > Sent: Tuesday, January 25, 2000 10:16 AM
> > To: Tommy Thorn
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: drop & take [was: fixing typos in Haskell-98]
> >
> > > IMHO, that would be the _insane_ definitions :-) Firstly, nothing
> > > suggests to me that rationale of such behaviour.
> >
> > The rationale is:
> > 1. these are useful functions
> > 2. if this is insane, so is python. The corresponding python is:
> >
> > def take list n: return list[:n]
> > def drop list n: return list[n:]
> >
> > Python interpreter example:
> > >>> list="abcdef"
> > >>> list[:-2]
> > 'abcd'
> > >>> list[-2:]
> > 'ef'
> > >>>
> >
> > 3. think of n as being calculated 'mod' length of the list
> > take n list | n<0 = take (n `mod` (length list)) list
> > drop n list | n<0 = drop (n `mod` (length list)) list
> > --(equivalent definitions)
> >
> > > Secondly, it would mean loosing an important set of laws:
> >
> > > drop n . drop m === drop (n + m)
> > > take n . take m === take (n + m)
> > > (which, I note in passing, is broken also by suggestion A)
> >
> > All the proposals break this law as well, so I this argument is weak (if
> > not insane :-))
> >
> > -Alex-
> > ___________________________________________________________________
> > S. Alexander Jacobson Shop.Com
> > 1-212-697-0184 voice The Easiest Way To Shop
> >
> >
> > On Mon, 24 Jan 2000, Tommy Thorn wrote:
> >
> > > S. Alexander Jacobson writes:
> > > > 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)
> > > ....
> > > > These are also sane definitions..
> > >
> > >
> > >
> > > Regards,
> > >
> > > Tommy
> > >
> >
> >
> >
> >
>