Show ASCII table: Difference between revisions

m
→‎{{header|Haskell}}: Applied Ormolu
m (fix category)
m (→‎{{header|Haskell}}: Applied Ormolu)
Line 1,816:
 
=={{header|Haskell}}==
<lang haskell>import Data.List.SplitChar (chunksOfchr)
import Data.List (transpose)
import Data.CharList.Split (chrchunksOf)
 
main :: IO ()
main = putStrLn asciiTable
 
asciiTable :: String
asciiTable =
unlines $
(justifyLeft 12 ' ' =<<) <$>
<$> transpose
transpose (chunksOf 16 $ asciiEntry <$> [32 .. 127])
 
asciiEntry :: Int -> String
asciiEntry n
| null k = k
| otherwise = concat [justifyRight 4 ' ' (show n), " : ", k]
concat
[justifyRight 4 ' ' (show n), " : ", k]
where
k = asciiName n
 
asciiName :: Int -> String
asciiName n
Line 1,843 ⟶ 1,846:
| 127 == n = "Del"
| otherwise = [chr n]
 
justifyLeft, justifyRight :: Int -> Char -> String -> String
justifyLeft n c s = take n (s <> replicate n c)
justifyRight n c = (drop . length) <*> (replicate n c <>)</lang>
{{Out}}
9,659

edits