2533: Generic functions that take integral arguments should work the same way as their prelude counterparts

Gwern Branwen gwern0 at gmail.com
Sat Aug 23 15:46:02 EDT 2008


On 2008.08.23 17:33:55 -0000, kahl at cas.mcmaster.ca scribbled 0.9K characters:
> Neil Mitchell <ndmitchell at gmail.com> wrote:
>  >
>  > > Hi
>  > >
>  > >> The Prelude functions drop, take, and splitAt are unfailing (never
>  > >> call error). This patch changes the Data.List generic versions to
>  > >> behave the same way. At present, they call error on negative
>  > >> arguments.
>  > >
>  > > I had always just assumed that take and genericTake did the same
>  > > thing, so had never even realised this problem existed. I'd call this
>  > > a bug, that needs fixing.
>  >
>  > Maybe the bug is in 'drop', 'take' and 'splitAt' and it was intended to
>  > fix it in 'generic' variants. Is there a good reason why to ignore
>  > negative number arguments? It may hide bugs.
>
> A similar argument could be made against ``take 5 [] = []''.
>
> A different solution would be using Nat or Natural as arguments here ---
> then the conversion introduces an obvious place to check for errors.
>
> Wolfram

I've actually long wondered about this: why don't more functions use Nat where it'd make sense? It can't be because Nat is hard to define - I'd swear I've seen many definitions of Nat (if not dozens when you count all the type-level exercises which include one).

--
gwern
ISSSP SADT NSV Rachel HAMASMOIS & Lindows wire ASPIC clandestine
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/libraries/attachments/20080823/580d07d9/attachment-0001.bin


More information about the Libraries mailing list