infixl

9

!!

(

!!

)

::

[

a

]

->

Int

->

a

#

if

defined

(

USE_REPORT_PRELUDE

)

xs

!!

n

|

n

<

0

=

errorWithoutStackTrace

"Prelude.!!: negative index"

[]

!!

_

=

errorWithoutStackTrace

"Prelude.!!: index too large"

(

x

:

_

)

!!

0

=

x

(

_

:

xs

)

!!

n

=

xs

!!

(

n

-

1

)

#

else

-- We don't really want the errors to inline with (!!).

-- We may want to fuss around a bit with NOINLINE, and

-- if so we should be careful not to trip up known-bottom

-- optimizations.

tooLarge

::

Int

->

a

tooLarge

_

=

errorWithoutStackTrace

(

prel_list_str

++

"!!: index too large"

)

negIndex

::

a

negIndex

=

errorWithoutStackTrace

$

prel_list_str

++

"!!: negative index"

xs

!!

n

|

n

<

0

=

negIndex

|

otherwise

=

foldr

(

\

x

r

k

->

case

k

of

0

->

x

_

->

r

(

k

-

1

))

tooLarge

xs

n

#

endif