lawful-conversions: Lawful typeclasses for bidirectional conversion between types

[ conversion, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

Summary

Lawful typeclasses capturing three patterns of bidirectional mapping and forming a layered hierarchy with an ascending strictness of laws.

  1. IsSome: Smart constructor

  2. IsMany: Lossy conversion

  3. Is: Isomorphism or lossless conversion

The conversion problem

Have you ever looked for a toString function? How often do you import Data.Text.Lazy only to call its Data.Text.Lazy.fromStrict? How about importing Data.ByteString.Builder only to call its Data.ByteString.Builder.toLazyByteString and then importing Data.ByteString.Lazy only to call its Data.ByteString.Lazy.toStrict?

Those all are instances of one pattern. They are conversions between different representations of the same information. Codebases that don't attempt to abstract over this pattern tend to be sprawling with this type of boilerplate. It's noise to the codereader, it's a burden to the implementor and the maintainer.

Why another conversion library?

Many libraries exist that approach the conversion problem. However most of them provide lawless typeclasses leaving it up to the author of the instance to define what makes a proper conversion. This results in inconsistencies across instances, their behaviour not being evident to the user and no way to check whether an instance is correct.

This library tackles this problem with a lawful typeclass hierarchy, making it evident what any of its instances do and it provides property-tests for you to validate your instances.

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.1.1, 0.1.2
Change log CHANGELOG.md
Dependencies base (>=4.12 && <5), bytestring (>=0.10 && <0.13), containers (>=0.6 && <0.8), hashable (>=1 && <2), primitive (>=0.7 && <0.10), profunctors (>=5 && <6), QuickCheck (>=2.13 && <3), text (>=1.2 && <2.2), unordered-containers (>=0.2 && <0.3), vector (>=0.12 && <0.14) [details]
License MIT
Copyright (c) 2022 Nikita Volkov
Author Nikita Volkov <nikita.y.volkov@mail.ru>
Maintainer Nikita Volkov <nikita.y.volkov@mail.ru>
Revised Revision 5 made by NikitaVolkov at 2024-12-04T06:18:42Z
Category Conversion
Home page https://github.com/nikita-volkov/lawful-conversions
Bug tracker https://github.com/nikita-volkov/lawful-conversions/issues
Source repo head: git clone git://github.com/nikita-volkov/lawful-conversions.git
Uploaded by NikitaVolkov at 2024-12-03T02:48:06Z
Distributions
Downloads 31 total (31 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-12-03 [all 1 reports]