Skip to content

[#670] Make length polymorphic in its return value

Nikolay Yakimov requested to merge lierdakil/#670-polymorphic-length into master

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

    • I checked whether I should update the docs and did so if necessary:
    • I updated changelog files of all affected packages released to Hackage if my changes are externally visible.

Stylistic guide (mandatory)

Merge request reports

Loading