lawful-conversions: Lawful typeclasses for bidirectional conversion between types
Summary
Lawful typeclasses capturing three patterns of bidirectional mapping and forming a layered hierarchy with an ascending strictness of laws.
Smart constructor
Canonicalization or lossy conversion
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 fromStrict
? How
about importing Data.ByteString.Builder
only to call its
toLazyByteString
and then importing
Data.ByteString.Lazy
only to call its 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.
Prior work and acknowledgements
This library is a direct successor of the "isomorphism-class" library, expanding upon the patterns discovered there. It also shares some ideas with "control-iso" and "type-iso".
Downloads
- lawful-conversions-0.1.6.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
Versions [RSS] | 0.1, 0.1.1, 0.1.2, 0.1.2.1, 0.1.2.2, 0.1.3, 0.1.4, 0.1.4.1, 0.1.5, 0.1.6 |
---|---|
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), time (>=1.9 && <2), unordered-containers (>=0.2 && <0.3), uuid-types (>=1.0 && <1.1), 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> |
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-23T12:08:58Z |
Distributions | LTSHaskell:0.1.4.1, Stackage:0.1.6 |
Reverse Dependencies | 1 direct, 89 indirect [details] |
Downloads | 192 total (192 in the last 30 days) |
Rating | (no votes yet) [estimated by Bayesian average] |
Your Rating | |
Status | Docs uploaded by user Build status unknown [no reports yet] |