Commatizing numbers: Difference between revisions

Content added Content deleted
(→‎{{header|Go}}: Added Haskell)
m (→‎{{header|Haskell}}: (specified imports, applied hlint))
Line 458: Line 458:
<lang haskell>#!/usr/bin/env runhaskell
<lang haskell>#!/usr/bin/env runhaskell


import Control.Monad
import Control.Monad (forM_)
import Data.Char
import Data.Char (isDigit)
import Data.List
import Data.List (intercalate)
import Data.Maybe
import Data.Maybe (fromMaybe)


{-
{-
Line 497: Line 497:
commatize2 [] _ _ = []
commatize2 [] _ _ = []
commatize2 str sep by =
commatize2 str sep by =
let (pfx, sfx) = span (not . isDigitOrPeriod) str
let (pfx, sfx) = break isDigitOrPeriod str
(number, sfx2) = span isDigitOrPeriod sfx
(number, sfx2) = span isDigitOrPeriod sfx
in pfx ++ processNumber number sep by ++ sfx2
in pfx ++ processNumber number sep by ++ sfx2
Line 519: Line 519:
]
]


main = do
main :: IO ()
main =
forM_ input $ \(str, by, sep) -> do
forM_ input $ \(str, by, sep) -> do
putStrLn str
putStrLn str
putStrLn $ commatize str by sep
putStrLn $ commatize str by sep
putStrLn ""
putStrLn ""</lang>
</lang>
{{out}}
{{out}}
<pre>
<pre>