length -package:vector -package:protolude package:relude

Returns the size/length of a finite structure as an Int. The default implementation just counts elements starting with the leftmost. Instances for structures that can compute the element count faster than via element-by-element counting, should provide a specialised implementation.

Examples

Basic usage:
>>> length []
0
>>> length ['a', 'b', 'c']
3

>>> length [1..]
* Hangs forever *
Returns the size/length of a finite structure as an Int.

Examples

Basic usage:
>>> bilength (True, 42)
2
>>> bilength (Right 42)
1
>>> bilength (BiList [1,2,3] [4,5])
5
>>> bilength (BiList [] [])
0
On infinite structures, this function hangs:
> bilength (BiList [1..] [])
* Hangs forever *
The genericLength function is an overloaded version of length. In particular, instead of returning an Int, it returns any type which is an instance of Num. It is, however, less efficient than length.
>>> genericLength [1, 2, 3] :: Int
3

>>> genericLength [1, 2, 3] :: Float
3.0