BSD-3-Clause licensed and maintained by Iustin Pop
This version can be pinned in stack with:prefix-units-0.3.0.1@sha256:9ed174c705e2e5fd5dd191f3af17239ae18cd5cc4824ddb21b5875db033dba75,3780

Module documentation for 0.3.0.1

Depends on 1 package(full list with versions):

prefix-units package

This package defines a datatype (Unit) and associated parsing/formatting functions so that command line applications can handle “nice” values like:

$ cmd create-file foo 100G
Done.
$ cmd ls-file foo
Size is 100Gi
$ cmd ls-files
foo 100Gi
bar  14Ki

And so on. For details on the API, look at the Haddock documentation for the Data.Prefix.Units module.

For building and installing, cabal configure and related commands are enough. Run cabal configure --enable-tests && cabal build && cabal test if you want to run the unit-tests.

The library is designed to have very few dependencies (only base and a few GHC extensions), so that it’s trivial to use it in projects. Hence the use of some hand-coded conversions instead of using TemplateHaskell to generate them automatically.

GitHub Workflow Status Codecov

TODO

The current interface of the library works, but is not nicely composable. I’m still looking for a nicer way to expose the parsing functionality.

Currently, the IEC (binary) and SI units are mixed in the same data-type. This works, but at some level I think two separate types would be more “correct”, at the expense of a more complex API.

The RationalConvertible type class has only a few instances; ideally we’d have instance Integral a => RationalConvertible a and similar for Fractional, but this doesn’t work as such in Haskell, so we’re stuck with the manual derivation.

The current behaviour is case-sensitive for all units in ParseExact mode, which means that one has to use (in this mode) Ki for the binary unit Kibi. This seems suboptimal, since the binary units are unique irrespective of casing.

Changes

Version 0.3.0.1

released Thu, 27 Apr 2023

It turns out that even if cabal check shows no warnings, Hackage doesn’t accept packages with very old cabal version constraints. So this release bumps that, which in turns makes cabal check actually start to show warnings, so modernise the cabal file as a result.

There are no code changes compared to 0.3.0, so this is a no-op release from the point of view of functionality.

Version 0.3.0

released Wed, 26 Apr 2023

  • Add the new quecto/ronto/ronna/quetta units. I didn’t think I’d ever have to extend the list of units! Not sure entirely if these should be part of the parseKMGT function, since they’re high enough to be out of normal computer units, but they do have lower/upper versions, so adding them seems the right thing.

Version 0.2.0

released Sun, 22 Nov 2015

  • Incompatible API change to cleanup some initial design decisions: the two level FormatOption/FormatMode model is removed, the fixed unit of FormatOption is moved to a new constructor FormatMode, and FormatOption is removed entirely. This should be a simpler API, at the cost of breaking compatibility.
  • Fixed issue #3 (No support for negative numbers).
  • Worked around issue #1 (Add ‘base’ unit) by adding a mode that disables scaling; it should have the same effect without introducing an artificial unit.

Version 0.1.0.2

released Sun, 23 Nov 2014

  • Trivial release for compatibility with QuickCheck 2.7 and older HUnit packages as found in Wheezy.
  • The release switches the test suite to use Cabal macros, which might create issues in some cases.
  • Fixed issue #2 (Wrong formatting for small numbers in SI mode).

Version 0.1.0.1

released Mon, 19 May 2014

  • Trivial release updating upper package bounds (for testing), updating homepage/related settings as part of move to github, and fixing a few documentation issues.

Version 0.1.0

released Thu, 03 May 2012

  • Initial release.