summaryrefslogtreecommitdiff
path: root/lib/Postdelay/TimeSpec/Units.hs
diff options
context:
space:
mode:
authorGregor Kleen <aethoago@141.li>2017-02-16 19:03:30 +0100
committerGregor Kleen <aethoago@141.li>2017-02-16 19:03:30 +0100
commit4343e02ca8431e61e2dc1755d1288dd6c55c9a23 (patch)
tree2f1397eb4c8649dffb7ae2adaedfd101bdda4fab /lib/Postdelay/TimeSpec/Units.hs
parent333ea946916b005134e7ba249178acad4858a67d (diff)
downloadpostdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.tar
postdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.tar.gz
postdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.tar.bz2
postdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.tar.xz
postdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.zip
Bounded numeric parsers
Diffstat (limited to 'lib/Postdelay/TimeSpec/Units.hs')
-rw-r--r--lib/Postdelay/TimeSpec/Units.hs9
1 files changed, 1 insertions, 8 deletions
diff --git a/lib/Postdelay/TimeSpec/Units.hs b/lib/Postdelay/TimeSpec/Units.hs
index a094ea3..4874ce9 100644
--- a/lib/Postdelay/TimeSpec/Units.hs
+++ b/lib/Postdelay/TimeSpec/Units.hs
@@ -56,14 +56,7 @@ instance HasResolution p => VectorSpace (Fixed p) where
56 56
57 57
58timeLength :: StringParser s m => m Time 58timeLength :: StringParser s m => m Time
59timeLength = (*^) <$> lexeme rational <*> timeUnit <?> "Length of time" 59timeLength = (*^) <$> lexeme (boundedRational False $ 0 <=..< PosInf) <*> timeUnit <?> "Length of time"
60
61rational :: forall s m n. (StringParser s m, Fractional n, Num n) => m n
62rational = combine <$> some digitChar <*> option [] (char '.' *> many digitChar) <?> "Decimal number"
63 where
64 combine :: [Char] -> [Char] -> n
65 combine (map fromDigit -> whole) (map fromDigit -> fractional)
66 = foldl' (\i l -> i * 10 + l) 0 whole + (foldr' (\h t -> h + t / 10) 0 fractional) / 10
67 60
68timeUnit :: StringParser s m => m Time 61timeUnit :: StringParser s m => m Time
69timeUnit = label "Unit of time" . choice $ 62timeUnit = label "Unit of time" . choice $