Multiplication tables: Difference between revisions
m
→{{header|Haskell}}: (Layout)
(→{{header|Haskell}}: Switched core type from [Int] to Maybe Int) |
m (→{{header|Haskell}}: (Layout)) |
||
Line 2,242:
=={{header|Haskell}}==
<lang haskell>
(\x ->
((\y ->
range = [1 .. n]
▲multTable n =
▲ (\y -> if y < x then Nothing else Just (x * y))
▲ <$> range
▲ where range = [1..n]
tableString :: [[Maybe Int]] -> String
tableString tbl = unlines $ (concat . (fmt <$>)) <$> tbl
where
pad = " "
fmt Nothing = pad
where
▲ fmt Nothing = pad
▲ fmt (Just n) = drop (length s) (pad ++ s)
▲ where
▲ s = show n
main :: IO ()
|