[Haskell-cafe] [Haskell] [ANN] quantities 0.3.0

Auke Booij auke at tulcod.com
Tue Apr 15 20:13:31 UTC 2014

On 15 April 2014 20:29, John David Reaver <jdreaver at adlerhorst.com> wrote:
> Hello! I am happy to publicly announce the quantities package:

I think haskell-cafe is more appropriate for these kinds of libraries.
Anyway, welcome.

> From the description on Hackage:
>    A library for creating and manipulating physical quantities,
>    which are a numerical value associated with a unit of
>    measurement. Included is an expression parser and a huge list
>    of predefined quantities with which to parse strings into a
>    Quantity datatype. Once created, a quantity can be converted
>    to different units or queried for its dimensionality. A user
>    can also operate on quantities arithmetically, and doing so
>    uses automatic unit conversion and simplification.

not sure if "quantities" is an appropriate name for your package: an
integer, a float, complex numbers - those are quantities. doesn't this
package parse units?

> Just to get a taste of how this package works, here are some
> examples:

why can i only "unsafely" create quantities using strings? what if i
know upfront what kind of a unit i want to deal with? from the looks
of it, this library is only good for dealing with human-readable input
- surely that's not the only use case you had in mind?

> >>> fromString "min => s"
> Right 60.0 second

can't we find some elegant way to express this in haskell, instead of
having to invent a scripting language of sorts?
On a similar note, your "magnitude :: Quantity -> Double" sounds a bit
like unsafeCoerce: why would you want to forget that your quantity has
a unit?

>From your documentation:

> >>> fromString "m => 3 ft"
> Left (ScalingFactorError 3.0 foot)

Why isn't the outcome of this 3.28084/3=1.09361 or something along
those lines? (this is just a suggestion, I'm not saying this is a bad

> >>> fromString "2 ft + 6 in => ft"
> Right 2.5 foot

Oh, so you are trying to support arbitrary arithmetical input!
Then again, there is no way to add two "Quantity"s.

I have the feeling the goal of your package is a bit unclear: do you
want to implement a framework to type-safely compute with units? Or do
you just want to write something that parses string input to typed

In the former case, have you considered the discussion on the haskellwiki [1]?

In the latter case, why don't you write it on top of an existing units package?

Well, that was a big rant, I hope you can use some of it.


[1]: http://www.haskell.org/haskellwiki/Physical_units

More information about the Haskell-Cafe mailing list