| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Morley.Prelude.Length
Description
Polymorphic length
Synopsis
- length :: (Integral i, Container a, DefaultToInt (IsIntSubType Length i) i) => a -> i
Documentation
length :: (Integral i, Container a, DefaultToInt (IsIntSubType Length i) i) => a -> i Source #
Polymorphic version of length.
Defaults to Int, same as the non-polymorphic version, if return value is
ambiguous.
>>>let list = [1..100]
>>>:t length listlength list :: Int
>>>length list :: Word100>>>length list :: Int100>>>length list :: Word63100>>>length list :: Natural100>>>length list :: Integer100>>>length list :: Word8... ... error: ... Can not safely cast 'Morley.Prelude.Length.Length' to 'Word8': ... 'Morley.Prelude.Length.Length' is not a subtype of 'Word8' ...
One caveat that with an unsuitable monomorphic type, length will also default
to Int:
>>>length list :: Bool... ... error: ... Couldn't match type ‘Bool’ with ‘Int’ ...
However, this lets us avoid the issue with integral literals.