leftPadInternal :: String -> Int -> Char -> String
leftPadInternal str rem ch =
if (rem <= 0) then
str
else
leftPadInternal ([ch] ++ str) (rem - 1) ch
leftPad :: String -> Int -> Maybe Char -> String
leftPad str len ch =
case ch of
Just c -> leftPadInternal str (len - length str) c
Nothing -> leftPadInternal str (len - length str) '.'
main :: IO ()
main = do let z = leftPad "1" 1 Nothing
putStrLn $ "" ++ show z
let z = leftPad "2" 2 Nothing
putStrLn $ "" ++ show z
let z = leftPad "3" 3 Nothing
putStrLn $ "" ++ show z
let z = leftPad "4" 4 Nothing
putStrLn $ "" ++ show z
let z = leftPad "5" 5 Nothing
putStrLn $ "" ++ show z
let z = leftPad "hello" 7 Nothing
putStrLn $ "" ++ show z
let z = leftPad "foo" 6 Nothing
putStrLn $ "" ++ show z
let z = leftPad "foo" 3 Nothing
putStrLn $ "" ++ show z
let z = leftPad "foobar" 3 Nothing
putStrLn $ "" ++ show z
let z = leftPad "foo" 6 (Just '?')
putStrLn $ "" ++ show z