41 lines
20 KiB
HTML
41 lines
20 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Data.Quantity</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
|
|
window.onload = function () {pageLoad();setSynopsis("mini_Data-Quantity.html");};
|
|
//]]>
|
|
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">MissingH-1.3.0.1: Large utility library</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>Copyright (C) 2006-2011 John Goerzen</td></tr><tr><th>License</th><td>BSD3</td></tr><tr><th>Maintainer</th><td>John Goerzen <jgoerzen@complete.org> </td></tr><tr><th>Stability</th><td>provisional</td></tr><tr><th>Portability</th><td>portable</td></tr><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><p class="caption">Data.Quantity</p></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Tools for rendering sizes</p><p>Written by John Goerzen, jgoerzen@complete.org </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:renderNum">renderNum</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Real">Real</a> a) => <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a> -> a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:renderNums">renderNums</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Real">Real</a> a) => <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a> -> [a] -> [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>]</li><li class="src short"><a href="#v:parseNum">parseNum</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Read.html#t:Read">Read</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Fractional">Fractional</a> a) => <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Either.html#t:Either">Either</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> a</li><li class="src short"><a href="#v:parseNumInt">parseNumInt</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Read.html#t:Read">Read</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integral">Integral</a> a) => <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Either.html#t:Either">Either</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> a</li><li class="src short"><a href="#v:quantifyNum">quantifyNum</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Real">Real</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Floating">Floating</a> b, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> b) => <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a> -> a -> (b, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Char.html#t:Char">Char</a>)</li><li class="src short"><a href="#v:quantifyNums">quantifyNums</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Real">Real</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Floating">Floating</a> b, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> b) => <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a> -> [a] -> ([b], <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Char.html#t:Char">Char</a>)</li><li class="src short"><span class="keyword">data</span> <a href="#t:SizeOpts">SizeOpts</a> = <a href="#v:SizeOpts">SizeOpts</a> {<ul class="subs"><li><a href="#v:base">base</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></li><li><a href="#v:powerIncr">powerIncr</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></li><li><a href="#v:firstPower">firstPower</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></li><li><a href="#v:suffixes">suffixes</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></li></ul>}</li><li class="src short"><a href="#v:binaryOpts">binaryOpts</a> :: <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></li><li class="src short"><a href="#v:siOpts">siOpts</a> :: <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><a name="v:renderNum" class="def">renderNum</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Real">Real</a> a)</td><td class="doc empty"> </td></tr><tr><td class="src">=> <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></td><td class="doc empty"> </td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></td><td class="doc"><p>Precision of the result</p></td></tr><tr><td class="src">-> a</td><td class="doc"><p>The number to examine</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Render a number into a string, based on the given quantities. This is
|
|
useful for displaying quantities in terms of bytes or in SI units. Give this
|
|
function the <code><a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></code> for the desired output, and a precision (number of
|
|
digits to the right of the decimal point), and you get a string output.</p><p>Here are some examples:</p><pre>Data.Quantity> renderNum binaryOpts 0 1048576
|
|
"1M"
|
|
Data.Quantity> renderNum binaryOpts 2 10485760
|
|
"10.00M"
|
|
Data.Quantity> renderNum binaryOpts 3 1048576
|
|
"1.000M"
|
|
Data.Quantity> renderNum binaryOpts 3 1500000
|
|
"1.431M"
|
|
Data.Quantity> renderNum binaryOpts 2 (1500 ** 3)
|
|
"3.14G"</pre><pre>Data.Quantity> renderNum siOpts 2 1024
|
|
"1.02k"
|
|
Data.Quantity> renderNum siOpts 2 1048576
|
|
"1.05M"
|
|
Data.Quantity> renderNum siOpts 2 0.001
|
|
"1.00m"
|
|
Data.Quantity> renderNum siOpts 2 0.0001
|
|
"100.00u"</pre><p>If you want more control over the output, see <code><a href="Data-Quantity.html#v:quantifyNum">quantifyNum</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:renderNums" class="def">renderNums</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Real">Real</a> a)</td><td class="doc empty"> </td></tr><tr><td class="src">=> <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></td><td class="doc empty"> </td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></td><td class="doc"><p>Prevision of the result</p></td></tr><tr><td class="src">-> [a]</td><td class="doc"><p>The numbers to examine</p></td></tr><tr><td class="src">-> [<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a>]</td><td class="doc"><p>Result</p></td></tr></table></div><div class="doc"><p>Like <code><a href="Data-Quantity.html#v:renderNum">renderNum</a></code>, but operates on a list of numbers. The first number
|
|
in the list will be evaluated for the suffix. The same suffix and scale will
|
|
be used for the remaining items in the list. See <code><a href="Data-Quantity.html#v:renderNum">renderNum</a></code> for more
|
|
examples.</p><p>Also, unlike <code><a href="Data-Quantity.html#v:renderNum">renderNum</a></code>, the %f instead of %g printf format is used so that
|
|
"scientific" notation is avoided in the output.</p><p>Examples:</p><pre>*Data.Quantity> renderNums binaryOpts 3 [1500000, 10240, 104857600]
|
|
["1.431M","0.010M","100.000M"]
|
|
*Data.Quantity> renderNums binaryOpts 3 [1500, 10240, 104857600]
|
|
["1.465K","10.000K","102400.000K"]</pre></div></div><div class="top"><p class="src"><a name="v:parseNum" class="def">parseNum</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Read.html#t:Read">Read</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Fractional">Fractional</a> a)</td><td class="doc empty"> </td></tr><tr><td class="src">=> <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></td><td class="doc"><p>Information on how to parse this data</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></td><td class="doc"><p>Whether to perform a case-insensitive match</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></td><td class="doc"><p>The string to parse</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Either.html#t:Either">Either</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> a</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Parses a String, possibly generated by <code><a href="Data-Quantity.html#v:renderNum">renderNum</a></code>. Parses the suffix
|
|
and applies it to the number, which is read via the Read class.</p><p>Returns Left "error message" on error, or Right number on successful parse.</p><p>If you want an Integral result, the convenience function <code><a href="Data-Quantity.html#v:parseNumInt">parseNumInt</a></code> is for
|
|
you.</p></div></div><div class="top"><p class="src"><a name="v:parseNumInt" class="def">parseNumInt</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Read.html#t:Read">Read</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integral">Integral</a> a)</td><td class="doc empty"> </td></tr><tr><td class="src">=> <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></td><td class="doc"><p>Information on how to parse this data</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></td><td class="doc"><p>Whether to perform a case-insensitive match</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></td><td class="doc"><p>The string to parse</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Either.html#t:Either">Either</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> a</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Parse a number as with <code><a href="Data-Quantity.html#v:parseNum">parseNum</a></code>, but return the result as
|
|
an <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integral">Integral</a></code>. Any type such as Integer, Int, etc. can be used for the
|
|
result type.</p><p>This function simply calls <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#v:round">round</a></code> on the result of <code><a href="Data-Quantity.html#v:parseNum">parseNum</a></code>. A
|
|
<code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-Exts.html#t:Double">Double</a></code> is used internally for the parsing of the numeric component.</p><p>By using this function, a user can still say something like 1.5M and get an
|
|
integral result. </p></div></div><div class="top"><p class="src"><a name="v:quantifyNum" class="def">quantifyNum</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Real">Real</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Floating">Floating</a> b, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> b) => <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a> -> a -> (b, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Char.html#t:Char">Char</a>)</p><div class="doc"><p>Takes a number and returns a new (quantity, suffix) combination.
|
|
The space character is used as the suffix for items around 0. </p></div></div><div class="top"><p class="src"><a name="v:quantifyNums" class="def">quantifyNums</a> :: (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Real">Real</a> a, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Floating">Floating</a> b, <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Ord.html#t:Ord">Ord</a> b) => <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a> -> [a] -> ([b], <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Char.html#t:Char">Char</a>)</p><div class="doc"><p>Like <code><a href="Data-Quantity.html#v:quantifyNum">quantifyNum</a></code>, but takes a list of numbers. The first number in
|
|
the list will be evaluated for the suffix. The same suffix and scale will
|
|
be used for the remaining items in the list. Please see <code><a href="Data-Quantity.html#v:renderNums">renderNums</a></code> for
|
|
an example of how this works.</p><p>It is invalid to use this function on an empty list. </p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:SizeOpts" class="def">SizeOpts</a></p><div class="doc"><p>The options for <code><a href="Data-Quantity.html#v:quantifyNum">quantifyNum</a></code> and <code><a href="Data-Quantity.html#v:renderNum">renderNum</a></code> </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:SizeOpts" class="def">SizeOpts</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><dl><dt class="src"><a name="v:base" class="def">base</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></dt><dd class="doc"><p>The base from which calculations are made</p></dd><dt class="src"><a name="v:powerIncr" class="def">powerIncr</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></dt><dd class="doc"><p>The increment to the power for each new suffix</p></dd><dt class="src"><a name="v:firstPower" class="def">firstPower</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></dt><dd class="doc"><p>The first power for which suffixes are given</p></dd><dt class="src"><a name="v:suffixes" class="def">suffixes</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></dt><dd class="doc"><p>The suffixes themselves</p></dd></dl><div class="clear"></div></div></td></tr></table></div></div><div class="top"><p class="src"><a name="v:binaryOpts" class="def">binaryOpts</a> :: <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></p><div class="doc"><p>Predefined definitions for byte measurement in groups of 1024, from 0 to
|
|
2**80 </p></div></div><div class="top"><p class="src"><a name="v:siOpts" class="def">siOpts</a> :: <a href="Data-Quantity.html#t:SizeOpts">SizeOpts</a></p><div class="doc"><p>Predefined definitions for SI measurement, from 10**-24 to 10**24. </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.16.0</p></div></body></html> |