snoyberg / mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers
153 stars 63 forks source link

Add sequence length function that returns (Index seq) #126

Closed AshleyYakeley closed 7 years ago

AshleyYakeley commented 7 years ago

The Index type family is used throughout the library to point into sequences, in may cases with an Integral constraint (e.g., take and drop). It would be useful to have a length function that gave the length of a sequence as Index seq.

This is my current workaround, which should be correct in all cases:

indexLength :: (MonoFoldable seq,Integral (Index seq)) => seq -> Index seq
indexLength = fromIntegral . olength64
snoyberg commented 7 years ago

Looks reasonable. Want to send a PR?

AshleyYakeley commented 7 years ago

OK, https://github.com/snoyberg/mono-traversable/pull/127

AshleyYakeley commented 7 years ago

Thanks!