summaryrefslogtreecommitdiffhomepage
path: root/Cost.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-30 13:12:32 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-30 13:13:52 -0400
commitb02bfe47d0a07b813dfd5bc3a78ad02c3673b493 (patch)
treed75d22bfefc04b0ae8b6d866d574eb734b14cd99 /Cost.hs
parent69a78f842a368ff143fca220584393afabd674f2 (diff)
downloadkeysafe-b02bfe47d0a07b813dfd5bc3a78ad02c3673b493.tar.gz
refactor
Diffstat (limited to 'Cost.hs')
-rw-r--r--Cost.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/Cost.hs b/Cost.hs
index 88d1d61..3e3e2df 100644
--- a/Cost.hs
+++ b/Cost.hs
@@ -17,10 +17,15 @@ totalCost :: Cost op -> (Seconds, [UsingHardware])
totalCost (CPUCost s) = (s, [UsingCPU])
raiseCostPower :: Cost c -> Entropy e -> Cost c
-raiseCostPower c (Entropy e) = adjustCost c (* 2^e)
+raiseCostPower c (Entropy e) = mapCost (* 2^e) c
-adjustCost :: Cost c -> (Seconds -> Seconds) -> Cost c
-adjustCost (CPUCost s) f = CPUCost (f s)
+mapCost :: (Integer -> Integer) -> Cost op -> Cost op
+mapCost f (CPUCost (Seconds n)) = CPUCost (Seconds (f n))
+
+showCostMinutes :: Cost op -> String
+showCostMinutes (CPUCost (Seconds n))
+ | n < 61 = "1 minute"
+ | otherwise = show (n `div` 60) ++ " minutes"
castCost :: Cost a -> Cost b
castCost (CPUCost s) = CPUCost s