I'm new to Haskell, but
(1) With regard to the second "law",
(take 1 . take 5) [1..]
does not appear to me to be the same as
take 6 [1..]
(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.
PCB
> -----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
> >
>
>
>
>