>>> length [] 0 >>> length ['a', 'b', 'c'] 3 >>> length [1..] * Hangs forever *
>>> length [] 0
>>> length ['a', 'b', 'c'] 3 >>> length [1..] * Hangs forever *
>>> length [] 0
>>> length ['a', 'b', 'c'] 3 >>> length [1..] * Hangs forever *@since base-4.8.0.0
>>> genericLength [1, 2, 3] :: Int 3 >>> genericLength [1, 2, 3] :: Float 3.0Users should take care to pick a return type that is wide enough to contain the full length of the list. If the width is insufficient, the overflow behaviour will depend on the (+) implementation in the selected Num instance. The following example overflows because the actual list length of 200 lies outside of the Int8 range of -128..127.
>>> genericLength [1..200] :: Int8 -56
>>> genericLength [1, 2, 3] :: Int 3 >>> genericLength [1, 2, 3] :: Float 3.0
>>> genericLength [1, 2, 3] :: Int 3 >>> genericLength [1, 2, 3] :: Float 3.0Users should take care to pick a return type that is wide enough to contain the full length of the list. If the width is insufficient, the overflow behaviour will depend on the (+) implementation in the selected Num instance. The following example overflows because the actual list length of 200 lies outside of the Int8 range of -128..127.
>>> genericLength [1..200] :: Int8 -56
>>> getLnBytesize ([1 .. 27] :: [Int]) 4
>>> getLnBytesize ([(1, 16), (5, 23), (2, 4), (3, 8), (0, 15) , (4, 42)] :: [(Int, Int)]) 2