Convert seconds to compound duration: Difference between revisions

m
→‎{{header|Haskell}}: Tidied parameterised variant.
(add Standard ML)
m (→‎{{header|Haskell}}: Tidied parameterised variant.)
Line 1,847:
<lang haskell>import Data.List (intercalate, mapAccumR)
 
----------------- COMPOUND DURATION STRINGS ----------------
 
durationString :: String -> String -> Int -> Int -> [String] -> Int -> String
String ->
durationString componentGap numberLabelGap daysPerWeek hoursPerDay xs n =
String ->
intercalate
Int ->
componentGap
Int (foldr->
[String] ->
(timeTags numberLabelGap)
Int []->
String
(zip (weekParts daysPerWeek hoursPerDay n) xs))
durationString
componentGap
numberLabelGap
daysPerWeek
hoursPerDay
xs
n =
intercalate
componentGap
( foldr
(timeTags numberLabelGap)
[]
(zip (weekParts daysPerWeek hoursPerDay n) xs))
)
 
timeTags :: String -> (Int, String) -> [String] -> [String]
Line 1,865 ⟶ 1,879:
weekParts :: Int -> Int -> Int -> [Int]
weekParts daysPerWeek hoursPerDay =
snd
snd . flip (mapAccumR byUnits) [0, daysPerWeek, hoursPerDay, 60, 60]
. flip
(mapAccumR byUnits)
snd . flip (mapAccumR byUnits) [0, daysPerWeek, hoursPerDay, 60, 60]
 
byUnits :: Int -> Int -> (Int, Int)
Line 1,874 ⟶ 1,891:
| otherwise = (1, rest)
 
---------------------------- TEST --------------------------
 
translation :: String -> Int -> Int -> Int -> String
translation local daysPerWeek hoursPerDay n =
intercalate " -> " $
[ show,
[show, durationString ", " " " daysPerWeek hoursPerDay (words local)] <*> [n]
durationString
", "
" "
daysPerWeek
hoursPerDay
(words local)
]
<*> [n]
 
main :: IO ()
9,659

edits