!! for Data.Stream

Conal Elliott conal at conal.net
Tue Oct 23 16:04:42 EDT 2007


I see that (!!) for Data.Stream has arguments reversed, compared to !! on
lists.  The Haddock comment, however, suggests otherwise.  Is the argument
reversal intended?  - Conal

>From Data.Stream:

-- | @xs !! n@ returns the element of the stream @xs@ at index
-- @n at . Note that the head of the stream has index 0.
-- 
-- /Beware/: passing a negative integer as the first argument will cause
-- an error.
(!!) :: Int -> Stream a -> a
(!!) n (Cons x xs)
  | n == 0    = x
  | n > 0     = (!!) (n - 1) xs
  | otherwise = error "Stream.!! negative argument"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/libraries/attachments/20071023/f6dece48/attachment.htm


More information about the Libraries mailing list