Opened 14 years ago

Closed 14 years ago

Last modified 45 years ago

#568 closed bug (Fixed)

take (-1) [] fails

Reported by: nobody Owned by: nobody
Priority: normal Milestone:
Component: Prelude Version: 5.0
Keywords: Cc:
Operating System: Architecture:
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

As described in the Haskell report, Prelude.take
applied to a negative argument and an empty list should
return an empty list. Hugs and HBC implements this
correctly, but GHC's implementation instead produces

  Exception: Prelude.take: negative index
I have two large programs, that work fine when compiled
with HBC, and fail because of this when compiled when
GHC. I have examined all direct calls to take in one of
them and I am 93.7% certain that they cannot be the
cause of the problem, so I suspect the offending call
to take comes from another prelude/library function...

Change History (4)

comment:1 Changed 14 years ago by simonmar

Logged In: YES 
user_id=48280

We don't have enough information to be able to analyse this 
problem further.  If the submitter is out there, could you 
perhaps provide us with the code that fails?  (and BTW, 
could you login or otherwise include your email address in 
the bug report next time so we can get in touch.  Thanks.)

comment:2 Changed 14 years ago by nobody

Logged In: NO 

Not enought information? The code that fails is in the
subject line!
You can easily verify it in ghci:

   % ghci
      ___         ___ _
     / _ \ /\  /\/ __(_)
    / /_\// /_/ / /  | |      GHC Interactive, version
5.00.2, For Haskell 98.
   / /_\\/ __  / /___| |      http://www.haskell.org/ghc/
   \____/\/ /_/\____/|_|      Type :? for help.

   Loading package std ... linking ... done.
   Prelude> take (-1) ""
   *** Exception: Prelude.take: negative index


I found code that seems consisent with this behavior in the
CVS repository
in fptools/libraries/core/GHC/List.lhs, in a section marked
/* hack away */
...

I also noted that in the revised Haskell 98 report, take
should always return
an empty list if the index is negative, i.e. even if the
argument list is
non-empty...

(I also discovered that the problem in my code was, I
suspected, not caused
by a direct call to take, but by a call to replicate with a
negative
argument...)

comment:3 Changed 14 years ago by simonmar

Logged In: YES 
user_id=48280

My apologies - I infered from your bug report that you were 
suggesting the bug was elsewhere in the prelude.  It's true 
that we haven't updated take/drop/splitAt with the recent 
changes in the Haskell 98 definition (I've now fixed that).

comment:4 Changed 14 years ago by simonmar

  • Status changed from assigned to closed
Logged In: YES 
user_id=48280

My apologies - I infered from your bug report that you were 
suggesting the bug was elsewhere in the prelude.  It's true 
that we haven't updated take/drop/splitAt with the recent 
changes in the Haskell 98 definition (I've now fixed that).
Note: See TracTickets for help on using tickets.