I have just recently started learning Haskell and started playing around with the idea of infinite lists and lazy evaluation. I constructed an infinite list and tried to access an element at a very, very distant index using the !!
operator. The issue is that the type signature for the !!
operator is the following:
(!!) :: [a] -> Int -> a
Which means it takes an Int
as an index to retrieve that element from the list.
Now, my problem occurs whenever I try to index something so distant that it overflow the Int
and therefore goes negative. What would then be the proper Haskell way of doing this?
Data.List.genericIndex supports using any Integral number to index, so you can use Integer if you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With