[GHC] #9585: Note about semantics of (!!) is not specific enough, if it's correct

#9585: Note about semantics of (!!) is not specific enough, if it's correct -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.9 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | Documentation bug Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- The definition of `(!!)` in `GHC.List`, copied below, has a vague note about semantics for the Prelude and HBC versions being different. I can't see the difference myself. If there really is a difference, the details should be in the comment. {{{#!hs -- | List index (subscript) operator, starting from 0. -- It is an instance of the more general 'Data.List.genericIndex', -- which takes an index of any integral type. (!!) :: [a] -> Int -> a #ifdef USE_REPORT_PRELUDE xs !! n | n < 0 = error "Prelude.!!: negative index" [] !! _ = error "Prelude.!!: index too large" (x:_) !! 0 = x (_:xs) !! n = xs !! (n-1) #else -- HBC version (stolen), then unboxified -- The semantics is not quite the same for error conditions -- in the more efficient version. -- xs !! (I# n0) | isTrue# (n0 <# 0#) = error "Prelude.(!!): negative index\n" | otherwise = sub xs n0 where sub :: [a] -> Int# -> a sub [] _ = error "Prelude.(!!): index too large\n" sub (y:ys) n = if isTrue# (n ==# 0#) then y else sub ys (n -# 1#) #endif }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9585 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9585: Note about semantics of (!!) is not specific enough, if it's correct -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: | Version: 7.9 libraries/base | Keywords: Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: Documentation bug | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by nomeata): * status: new => closed * resolution: => fixed Comment: After staring at the code for a few minutes, I also don’t see a difference – both evaluate `n` first, and then go down the list in the obvious manner. Some archaeology reveals: ceb68b9118fa883e88abfaa532fc78f6640cf17f changed the prelude definition, and before the change, `!!` would evaluate the list before the number. So you are right, the comment is wrong. I just removed it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9585#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9585: Note about semantics of (!!) is not specific enough, if it's correct
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: | Version: 7.9
libraries/base | Keywords:
Resolution: fixed | Architecture: Unknown/Multiple
Operating System: | Difficulty: Unknown
Unknown/Multiple | Blocked By:
Type of failure: | Related Tickets:
Documentation bug |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by Joachim Breitner
participants (1)
-
GHC