[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 15:22:55 UTC 2010


The following commit has been merged in the master branch:
commit 35e1ee060a3569758dced8c1ede476945ae9573b
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Apr 15 00:40:05 2008 -0500

    First stab at a parseNum

diff --git a/src/Data/Quantity.hs b/src/Data/Quantity.hs
index 9685a14..026fc7d 100644
--- a/src/Data/Quantity.hs
+++ b/src/Data/Quantity.hs
@@ -1,5 +1,5 @@
 {-
-Copyright (C) 2006 John Goerzen <jgoerzen at complete.org>
+Copyright (C) 2006-2008 John Goerzen <jgoerzen at complete.org>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 {- |
    Module     : Data.Quantity
-   Copyright  : Copyright (C) 2006 John Goerzen
+   Copyright  : Copyright (C) 2006-2008 John Goerzen
    License    : GNU GPL, version 2 or above
 
    Maintainer : John Goerzen <jgoerzen at complete.org> 
@@ -165,3 +165,16 @@ renderNums opts prec numbers =
               (printf ("%." ++ show prec ++ "f") num) ++ [suffix]
           (convnums, suffix) = 
               (quantifyNums opts numbers)::([Double], Char)
+
+parseNum :: Real a => SizeOpts -> String -> Either String a
+parseNum opts inp =
+    case reads inp of
+      [] -> Left "Couldn't parse numeric component of input"
+      [(num, "")] -> Right num  -- No suffix; pass number unhindered
+      [(num, suffix)] ->
+          case lookup suffix suffixMap of
+            Nothing -> Left $ "Unrecognized suffix " ++ show suffix
+            Just power -> Right $ num * ((base opts) ** power)
+      _ -> Left "Multiple parses for input"
+    where suffixMap = zip (suffixes opts) 
+                          (iterate (+ (powerIncr opts)) (firstPower opts))
\ No newline at end of file

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list