[#670] Make length polymorphic in its return value
Description
Problem: Unsafe.fromIntegral . length
has become widespread, but it
feels bad each time one has to use it.
Solution: Make length
polymorphic. Ensure the cast is safe(-ish) using
machinery from FromIntegral
(however the cast itself still has to be
unsafe because we're casting from Int
despite negative values being
nonsense). To reduce friction, use the incoherent instance trick to
force the return type to Int
on ambiguity (otherwise there's a lot of
pain with polymorphic integral literals)
Related issue(s)
Resolves #670 (closed)
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.