Giter VIP home page Giter VIP logo

quantities's Introduction

Quantities

Build Status

Unit conversion and manipulation library for Haskell.

Documentation

Check out the docs on Hackage.

Examples

We provide a string-parsing constructor to create quantities. This constructor is built using an expression parser, so arithmetic expressions can be used.

>>> fromString "25 m/s"
Right 25.0 meter / second
>>> fromString "fakeunit"
Left (UndefinedUnitError "fakeunit")
>>> fromString "ft + 12in"
Right 2.0 foot

fromString also supports unit conversions, by placing "=>" in between two valid expressions.

>>> fromString "min => s"
Right 60.0 second
>>> fromString "2 ft + 6 in => ft"
Right 2.5 foot

The convert function is used for unit conversions.

computation :: Either QuantityError Quantity
computation = do
  m  <- fromString "30 m"
  ft <- units <$> fromString "ft"
  convert m ft
>>> computation
Right 98.42519685039369 foot

Executable

An executable is included called quantities, which is an interface to the fromString function.

$ quantities -h
Usage: quantities [-vh] expression
$ quantities "10 bbl/sec => m^3/min"
95.39237695680004 meter ** 3 / minute
$ quantities "fakeunit"
UndefinedUnitError "fakeunit"

What units are defined?

We have already defined an extensive list of units and SI prefixes. To view them, check out this source file.

There is also functionality to modify this file, or create a totally new one.

How to Contribute

Head over to the Github repo to report an issue or create a patch. Also, non-code contributions are always welcome, especially in this early stage of development. That includes, but is not limited to:

  • API changes/suggestions
  • Code style suggestions
  • Unclear documentation

Don't feel shy to raise an issue! Any constructive criticism helps.

TODO

  • Handle temperature units. Simple temperature conversions are easy (celsius to farenheit), but compound units with temperatures are tougher.
  • Add ability to define units out of order; base quantity does not already have to be defined, as long as it is defined in the file.
  • Allow plural form of units. Try to find plural only if no other units can be parsed, or else "ms" will be a plural for meters.
  • Allow use of " to " instead of "=>". Because of parser architecture, need to detect either of these tokens before actually parsing units. Otherwise, it will think "to" is a bad unit.

quantities's People

Contributors

jdreaver avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.